Jump to content

attachments with mail()


jbatson

Recommended Posts

I have a piece of code that adds the attachment just fine but the message is never added, any ideas:

 

// ======================================================================

 

$mail_headers = "From: ".$var_from."\n";

 

if(isset($var_cc))

{

$mail_headers .= "CC:".$var_cc."\n";

}

 

if(stristr($var_attachments,'\''))

{

$var_array = explode('\'',$var_attachments);

$count = count($var_array) - 1;

$var_filename = $var_array[$count];

}

 

if(stristr($var_attachments,'/'))

{

$var_array = explode('/',$var_attachments);

$count = count($var_array) - 1;

$var_filename = $var_array[$count];

}

 

$file = fopen($var_attachments,'rb');

$data = fread($file,filesize($var_attachments));

fclose($file);

 

$data = chunk_split(base64_encode($data));

$semi_rand = md5(time());

$mime_boundary = $semi_rand;

 

$mail_headers .= "MIME-Version: 1.0"."\n";

$mail_headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\""."\n\n";

 

$email_message = "--".$mime_boundary."\n";

//$email_message = "--".$mime_boundary."\n";

//$email_message .= "Content-type: multipart/alternative"."\n";

 

$email_message .= "Content-Type: text/html; charset=iso-8859-1"."\n";

$email_message .= "Content-Transfer-Encoding: 7bit"."\n";

$email_message .= $var_message."More Testing"."\n\n";

 

 

$email_message .= "--".$mime_boundary."\n";

$email_message .= "Content-Type: application/octet-stream; name=\"".$var_filename."\""."\n";

$email_message .= "Content-Transfer-Encoding: base64"."\n";

$email_message .= "Content-Disposition: attachment; filename=\"".$var_filename."\""."\n\n";

$email_message .= $data."\n\n";

//$email_message .= "--".$mime_boundary."--"."\n";

$email_message .= "--".$mime_boundary."\n\n";

 

 

 

 

// ++++++++++++++++++++++++++++++++++

                        // THEN MAIL IT

                     

mail(to, subject, $email_message, $mail_headers)

 

// ======================================================================

 

Get the attachement but no message.

Link to comment
https://forums.phpfreaks.com/topic/75836-attachments-with-mail/
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.