PHP mail () eki Mac posta açılması değil

2 Cevap php

I am sending an email using PHP mail() and I can successfully receive and open the attachment (in this case a pdf) in almost every program i have access to. Except in mac mail where I am told that the file is corrupt. Has anyone else run into this problem before? Below is the script I am using:

//define the receiver of the email
$to = 'bionic.comms@hotmail.com';
//define the subject of the email
$subject = 'Email with Attachment';
//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 \n
$mime_boundary = "<<<--==+X[".md5(time())."]";

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


$headers .= "From: info@poundsandpennies.org.uk <info@poundsandpennies.org.uk>"."\n";

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

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

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

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

$message .= "Content-Type: application/octet-stream;\n";
$message .= " name=\"CTF-brochure.pdf\"" . "\n";
$message .= "Content-Transfer-Encoding: base64 \n";
$message .= "Content-Disposition: attachment;\n";
$message .= " filename=\"CTF_brochure.pdf\"\n";
$message .= "\n";
$message .= $fileContent;
$message .= "\n";
$message .= "--".$mime_boundary."--\n";

//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";

Şimdiden teşekkürler!

2 Cevap

Mac Mail, bir eki, İçerik Eğilimi inline için ayarlanmış olduğundan emin olun açmama önlemek için.

Hiçbir fikrim yok ne oluyor orada, ama ben her zaman kendi mail inşaat kod rulo çalışın kaç kişi şaşırdım.

Sadece SwiftMailer veya PHPMailer gibi bir kütüphane kullanarak düşündünüz mü? Hemen hemen her durumda, daha iyi biçimlendirme, daha az baş ağrısı, ve genellikle daha iyi performans alırsınız.