ckennerdale
Programmer
I have a form to email script which uses the mail() function
It successfulyy sends attachmentsi if the form has a 'file' element in which allows the user to select a file from their local hard drive.
what i would like to do is send an email with an attachmnet that I designate- ie like a virtual postcard.
I have sent the mail script the location of the file i want to attach both relative and absolute. But the attachment does not come thorough
does anyone have any expereince with this?
my code is below
<?
// * global variables received from a form or third party application via HTTP POST
global $mail_to, $mail_from, $mail_body_orig1, $mail_title, $file_name;
// * get time from server to give email unique id
$mail_boundary = md5(uniqid(time()));
//* mail header attributes including multipart email type and id
$mail_headers .= "From: $mail_from \n";
$mail_headers .= "MIME-Version: 1.0\r\n";
$mail_headers .= "Content-type: multipart/mixed;";
$mail_headers .= "boundary= \"$mail_boundary\"";
$mail_headers .= "\r\n\r\n";
//* mail body attributes
$new_mail_body .= "--$mail_boundary\n";
$new_mail_body .= "Content-type: text/plain; charset=us-ascii\r\n";
$new_mail_body .= "Content-transfer-encoding: 7bit\r\n\r\n";
$new_mail_body .= $mail_body_orig1;
$new_mail_body .= "\r\n";
// new 23/10/01
$new_mail_body .= $file_name;
$new_mail_body .= "\r\n";
//
//* mail attachment attributes including MIME type
$new_mail_body .= "--$mail_boundary\n";
$fp = fopen($file_name, "r"
$file = fread ($fp, filesize ($file_name));
$file = chunk_split(base64_encode($file));
$mime_type = $file_name_type;
$new_mail_body .= "Content-type:$mime_type; name=\"$file_name\"\r\n";
$new_mail_body .= "Content-transfer-encoding:base64\r\n\r\n";
$new_mail_body .= $file;
$new_mail_body .= "\r\n\r\n";
$new_mail_body .= "--$mail_boundary--";
//* convert variable if required for the mail() function and return
$mail_body = $new_mail_body;
$mail_subject = $mail_title;
return mail($mail_to , $mail_subject, $new_mail_body, $mail_headers);
?> Caspar Kennerdale
Senior Media Developer
It successfulyy sends attachmentsi if the form has a 'file' element in which allows the user to select a file from their local hard drive.
what i would like to do is send an email with an attachmnet that I designate- ie like a virtual postcard.
I have sent the mail script the location of the file i want to attach both relative and absolute. But the attachment does not come thorough
does anyone have any expereince with this?
my code is below
<?
// * global variables received from a form or third party application via HTTP POST
global $mail_to, $mail_from, $mail_body_orig1, $mail_title, $file_name;
// * get time from server to give email unique id
$mail_boundary = md5(uniqid(time()));
//* mail header attributes including multipart email type and id
$mail_headers .= "From: $mail_from \n";
$mail_headers .= "MIME-Version: 1.0\r\n";
$mail_headers .= "Content-type: multipart/mixed;";
$mail_headers .= "boundary= \"$mail_boundary\"";
$mail_headers .= "\r\n\r\n";
//* mail body attributes
$new_mail_body .= "--$mail_boundary\n";
$new_mail_body .= "Content-type: text/plain; charset=us-ascii\r\n";
$new_mail_body .= "Content-transfer-encoding: 7bit\r\n\r\n";
$new_mail_body .= $mail_body_orig1;
$new_mail_body .= "\r\n";
// new 23/10/01
$new_mail_body .= $file_name;
$new_mail_body .= "\r\n";
//
//* mail attachment attributes including MIME type
$new_mail_body .= "--$mail_boundary\n";
$fp = fopen($file_name, "r"
$file = fread ($fp, filesize ($file_name));
$file = chunk_split(base64_encode($file));
$mime_type = $file_name_type;
$new_mail_body .= "Content-type:$mime_type; name=\"$file_name\"\r\n";
$new_mail_body .= "Content-transfer-encoding:base64\r\n\r\n";
$new_mail_body .= $file;
$new_mail_body .= "\r\n\r\n";
$new_mail_body .= "--$mail_boundary--";
//* convert variable if required for the mail() function and return
$mail_body = $new_mail_body;
$mail_subject = $mail_title;
return mail($mail_to , $mail_subject, $new_mail_body, $mail_headers);
?> Caspar Kennerdale
Senior Media Developer