denewey Posted May 19, 2009 Share Posted May 19, 2009 I cannot seem to get multiple attachments to send with the php mail function. I am able to send an individual html attachment, but now I am trying to add an image attachment and it doesn't go. With the additional code for the image attachment the mail sends the first attachment but not the second. Here is the code I have: function mail_attached($to, $from, $subject, $message, $filename, $headers = '') { $unique_sep = md5(uniqid(time())); $headers .= "From: $from\n"; $headers .= "MIME-Version: 1.0\nContent-Type: multipart/mixed;boundary=\"$unique_sep\";\n"; $headers .= "charset=\"iso-8859-1\"\nContent-Transfer-Encoding:7bit\n\n"; $headers .= "If you are reading this, then your e-mail client does not support MIME.\n"; $headers .= "--$unique_sep\n"; $headers .= "Content-Type: text/html; name=\"" . $filename[0]['filename'] . "\"\n"; $headers .= "Content-Transfer-Encoding: 8bit\n"; $headers .= "Content-Disposition: attachment; filename=\"" . $filename[0]['filename'] . "\"\n\n"; echo "The file name1 is {$filename[0]['filename']}<br>";//DEBUG $filedata = implode("", file($filename[0]['file'])); $headers .= $filedata . "\n\n"; $headers .= "--$unique_sep--\n"; $headers .= "Content-Type: image/jpg; name=\"" . $filename[1]['filename'] . "\"\n"; $headers .= "Content-Transfer-Encoding: base64\n"; $headers .= "Content-Disposition: attachment; filename=\"" . $filename[1]['filename'] . "\"\n\n"; echo "The file name2 is {$filename[1]['filename']}<br>";//DEBUG $filedata2 = implode("", file($filename[1]['file'])); $headers .= chunk_split(base64_encode($filedata2)); $headers .= "--$unique_sep--\n"; mail($to, $subject, $message, $headers); } $date = time(); $handle = fopen("./forms/form12b25-" . $date . ".htm", "w+"); if($handle) { fwrite($handle, $HTML); fclose($handle); $f_array_1 = array('file'=>"./forms/form12b25-" . $date . ".htm",'mimetype'=>"text/plain",'filename'=>"form12b25-" . $date . ".htm"); $f_array_2 = array('file'=>"ballot-checked.jpg",'mimetype'=>"image/jpg",'filename'=>"ballot-checked.jpg"); $file_array = array($f_array_1, $f_array_2); mail_attached("[email protected]", "[email protected]", "form12b25 Submission", "form12b25 Submission Generated", $file_array); Does anyone have an idea of what I'm doing wrong? In the two debug lines where I echo the file names I am getting the correct names for each file. Thanks Link to comment https://forums.phpfreaks.com/topic/158738-multiple-mail-attachments/ Share on other sites More sharing options...
JonnoTheDev Posted May 19, 2009 Share Posted May 19, 2009 Does anyone have an idea of what I'm doing wrong? Yes; using the mail() function to send attachments. That's wrong in itself. Use the following package: http://pear.php.net/package/Mail_Mime Link to comment https://forums.phpfreaks.com/topic/158738-multiple-mail-attachments/#findComment-837356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.