Jump to content

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

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.