Jump to content

Multiple attachments not working


sholla

Recommended Posts

I want to attach two image files to an email. However, only the first file gets attached. I've tried all sorts of solutions and still I'm always back in the same spot. Pls can someone help me fix this script so that it works?

 


<body>
<?php
    $fileatttype = "image/jpeg"; 
    $fileattname = "sign.jpg";  //check
   
$to_addr = "[email protected]";
$from_addr = "[email protected]";
$subject = "Comments/feedback";
$message = '';

$headers = "From: $from_addr\r\n";

$mimetype = 'multipart/mixed';
$filename = 'photo.jpg';
$ffile = 'uploads/photo.jpg';
    $fileatt = "uploads/photo.jpg";	

$mimetype2 = 'image/jpeg';
$filename2 = 'sign.jpg';
$ffile2 = 'uploads/sign.jpg';
    $fileatt2 = "uploads/sign.jpg";

    $file = fopen($fileatt,'rb');
    $data = fread($file,filesize($fileatt));
    fclose($file);

    $file2 = fopen($fileatt2,'rb');
    $data2 = fread($file2,filesize($fileatt2));
    fclose($file2);	

$unique_sep = md5(uniqid(time()));

$headers .= "Content-Type: {$mimetype}; ".
"name=\"{$filename}\"\n";
$headers .= "Content-Transfer-Encoding: ".
"base64\n";
$headers .= chunk_split(base64_encode($data));
$headers .= "Content-Disposition: attachment\n\n";
$headers .= "--$unique_sep--\r\n";

$headers .= "Content-Type: {$mimetype}; ".
"name=\"{$filename2}\"\n";
$headers .= "Content-Transfer-Encoding: ".
"base64\n";
$headers .= chunk_split(base64_encode($data2));
$headers .= "Content-Disposition: attachment\n\n";
$headers .= "--$unique_sep--";


$success = mail($to_addr, $subject, $message, $headers);
if ($success)
	echo "<strong>Your information have been submited.<br>Thank you.</strong>";
else
	echo "An error occurred when sending the email to your email address";

?>
</body>

Link to comment
https://forums.phpfreaks.com/topic/120878-multiple-attachments-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.