PHP Forums Archive

e-mail with attachment corrupted

Tags: n/a

Tatiana posted on 2011-03-24 23:48:44 #

I copied here from the site the following script and changed the values ??of variables. The e-mail was sent with an attached pdf, but the pdf gets corrupted.

I believe the problem is with the Content-Transfer-Encoding, but do not know how to solve. Can someone help me!

function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {

ini_set(SMTP, "smtp.dominio.br" );
ini_set(smtp_port, 25 );
// function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
$file = "http://localhost/limesurveyDesenv/teste_mail.pdf";
$file_size = 48435.2;
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = "From: user@dominio.br\r\n";
$header .= "Reply-To: user@dominio.br \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/html; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$header .= "mensagem\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/pdf; name=\"teste_mail.pdf\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"teste_mail.pdf\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
if (mail("user@dominio.br ", "Assunto", "", $header)) {
echo "mail send ... OK"; // or use booleans here
} else {
echo "mail send ... ERROR!";
}
}

I thank you, anyone who can help me

Comments / discussions

Olaf posted on 2011-03-25 04:51:31 #

I guess it's the filesize what is 48435.2 for a value?