tags:

views:

80

answers:

1

I am using the script below and although I am receiving an email but I am not getting the content or the attachment. Does anyone know what I am doing wrong? This is set up on a clients server with a plesk control panel if that helps. I have had problems with mail on these servers before. I know that the script works on my server. Is there a setting somewhere that I can change to make the magic happen?

 //define the receiver of the email
$to = '[email protected]';
//define the subject of the email
$subject = 'Attachment bastard';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$mime_boundary = "<<<--==+X[".md5(time())."]";

$path = $_SERVER['DOCUMENT_ROOT'].'/drew/mail/';
$fileContent = chunk_split(base64_encode(file_get_contents($path.'CTF_brochure.pdf')));

$headers .= "From: [email protected] <[email protected]>\r\n";  

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
$headers .= " boundary=\"".$mime_boundary."\"";

$message .= "This is a multi-part message in MIME format.\r\n";
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";

$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "\r\n";
$message .= "Email content and what not: \r\n";
$message .= "This is the file you asked for! \r\n";
$message .= "--".$mime_boundary."\r\n";

$message .= "Content-Type: application/octet-stream;\r\n";
$message .= " name=\"CTF-brochure.pdf\"\r\n";
$message .= "Content-Transfer-Encoding: base64 \r\n";
$message .= "Content-Disposition: attachment;\r\n";
$message .= " filename=\"CTF_brochure.pdf\"\r\n";
$message .= "\r\n";
$message .= $fileContent;
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = mail($to, $subject, $message, $headers);
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";

EDIT

Noticed the ob_get_clean which was clearing my message.

A: 

Can you post the source from the email you receive?

mabwi
i'm afraid I can't as I am only receiving mail into a googlemail account. I have tried viewing the source but it is all pre-formatted.
Drew