Jump to content

Recommended Posts

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("denewey@gmail.com", "12b25@edgarfilingagent.com", "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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.