I have searched google and on this forum, i got handful of codes but doesn’t help…
anyway, here’s my problem…
i made a form with an attachment field, i want the attachment to send to my email…
i can receive the attachments but the contents are corrupt and some errors on
$file = fopen($fileatt,‘rb’);
$data = fread($file,filesize($fileatt));
fclose($file);
$msg_txt="";
the error said “failed to open stream” something like that
i guess the attachment is not carried by the functions…pls help me on this. pls pls pls
i got his codes right here…
email.php
<?
function is_valid_email($email)
{
return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email);
}
include 'function.php';
extract($_POST);
$name_from = $name;
$email_to = "edryanra@gmail.com";
$subject = "1st Class Bail Bonds Careers - New Application submitted by ".$name;
$message = "mensahe";
$att = $_FILES['resume_file']['name'];
if (!is_valid_email($email))
{
?>
<script type='text/javascript'>
alert("Invalid email. Please try again.");
window.location = 'careers_affiliates.htm';
</script>
<?
exit;
}
else{
//from, to, subject, message, attachment
mail_attachment($name_from, $email_to, $subject, $message, "$att");
}
?>
function.php
<?php
function mail_attachment ($from , $to, $subject, $message, $attachment){
$fileatt = $attachment; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
//$start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;
//$fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment
$fileatt_name = $attachment;
$email_from = $from; // Who the email is from
$email_subject = $subject; // The Subject of the email
$email_txt = $message; // Message that the email has in it
$email_to = $to; // Who the email is to
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$msg_txt="";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "
MIME-Version: 1.0
" .
"Content-Type: multipart/mixed;
" .
" boundary=\"{$mime_boundary}\"";
$email_txt .= $msg_txt;
$email_message .= "This is a multi-part message in MIME format.
" .
"--{$mime_boundary}
" .
"Content-Type:text/html; charset=\"iso-8859-1\"
" .
"Content-Transfer-Encoding: 7bit
" .
$email_txt . "
";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}
" .
"Content-Type: {$fileatt_type};
" .
" name=\"{$fileatt_name}\"
" .
//"Content-Disposition: attachment;
" .
//" filename=\"{$fileatt_name}\"
" .
"Content-Transfer-Encoding: base64
" .
$data . "
" .
"--{$mime_boundary}--
";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
?>
<script type='text/javascript'>
alert("Your application was successfully sent! Thank you!");
window.location = 'careers_affiliates.htm';
</script>
<?
} else {
?>
<script type='text/javascript'>
alert("Sorry but the email could not be sent. Please go back and try again!");
window.location = 'careers_affiliates.htm';
</script>
<?
}
}
?>
pls help…needed badly!..tnx