我尝试将电子邮件从服务器发送给收件人,没问题,电子邮件已发送。我在此电子邮件中有TEXT HTML和PDF附件...
问题是:我收到邮件,我收到PDF,但是没有文本!
如果您可以帮助,这是我的代码:)
$filepath = '../../path/file.pdf';
if (!preg_match("#^[a-z0-9._-]+@(hotmail|live|msn).[a-z]{2,4}$#", $email))
{
$br = "\r\n";
}
else
{
$br = "\n";
}
$message_html= "Content-Type: text/html; charset=\"ISO-8859-1\"".$br;
$message_html.= "Content-Transfer-Encoding: 8bit".$br;
$message_html.= '<!DOCTYPE html><html><head>
<title>mytitle</title>
</head>
<body>
<div>
my content!
</div
</body>
</html>';
$boundary = "-----=".md5(rand());
$boundary_alt = "-----=".md5(rand());
$subject = "mysubject";
$attached_file = file_get_contents($filepath);
$attached_file = chunk_split(base64_encode($attached_file));
$pos=strrpos($filepath,"/");
if($pos!==false)$file_name=substr($filepath,$pos+1);
else $file_name=$filepath;
$pos=strrpos($filepath,".");
if($pos!==false)$file_type="/".substr($filepath,$pos+1);
else $file_type="";
$attached = "\n\n". "--" .$boundary . "\nContent-Type: application".$file_type."; name=\"$file_name\"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"tickets.pdf\"\r\n\n".$attached_file . "--" . $boundary . "--";
//=====HEADER
$header = "To: ".$email." ".$br;
$header.= "From: frrrrrom".$br;
$header.= "Cc: cccccccc".$br;
$header.= "Reply-to: qdfqsf".$br;
$header.= "MIME-Version: 1.0".$br;
$header.= "Content-Type: multipart/mixed;".$br." boundary=\"$boundary\"".$br;
//==========
$body = $message_html.$attached;
mail($email,$subject,$body,$header);
如果必须调试它,我将删除附件的PDF,并检查它是否发送了文本,然后尝试重新添加文本。
另外,您可以尝试使用var_dump $ body和其他vars打印到屏幕上,并与我们共享,这样可以更轻松地发现问题。可能是因为您发送的内容与电子邮件发送的格式不匹配。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句