猿问

使用PHP Mail()发送附件?

使用PHP Mail()发送附件?

我需要发送带有邮件的pdf,这可能吗?


$to = "xxx";

$subject = "Subject" ;

$message = 'Example message with <b>html</b>';

$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'From: xxx <xxx>' . "\r\n";

mail($to,$subject,$message,$headers);

我错过了什么?


莫回无
浏览 1686回答 3
3回答

跃然一笑

对于PHP 5.5.27安全更新$file = $path.$filename;$content = file_get_contents( $file);$content = chunk_split(base64_encode($content));$uid = md5(uniqid(time()));$name = basename($file);// header$header = "From: ".$from_name." <".$from_mail.">\r\n";$header .= "Reply-To: ".$replyto."\r\n";$header .= "MIME-Version: 1.0\r\n";$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";// message & attachment$nmessage = "--".$uid."\r\n";$nmessage .= "Content-type:text/plain; charset=iso-8859-1\r\n";$nmessage .= "Content-Transfer-Encoding: 7bit\r\n\r\n";$nmessage .= $message."\r\n\r\n";$nmessage .= "--".$uid."\r\n";$nmessage .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";$nmessage .= "Content-Transfer-Encoding: base64\r\n";$nmessage .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";$nmessage .= $content."\r\n\r\n";$nmessage .= "--".$uid."--";if (mail($mailto, $subject, $nmessage, $header)) {&nbsp; &nbsp; return true; // Or do something here} else {&nbsp; return false;}
随时随地看视频慕课网APP
我要回答