通过对邮件格式的认识,我们可以写一个脚本来发送附件。代码并不长:
[php]
function mailsend($to, $subject, $message, $attach, $from, $replyto) {//定义边界线$boundary = uniqid();//生成邮件头$header = "from: $fromreply-to:$replytocontent-type: multipart/mixed; boundary=\"$boundary\"";//获取附件文件的mime类型$mimetype = mime_content_type($attach);//对附件文件进行编码和切分$fp = fopen($attach, "r");if ($fp) {$content = fread($fp, filesize($attach));$content = chunk_split(base64_encode($content));fclose($fp);}else {die("failed to open file…");}//生成邮件主体$body = "–$boundarycontent-type: text/plain; charset=utf-8;content-transfer-encoding: 8bit$message–$boundarycontent-type: $mimetype; name=$attachcontent-disposition: attachment; filename=$attachcontent-transfer-encoding: base64$content–$boundary–";//发送邮件mail($to, $subject, $body, $header) or die("failed to send mail…");}
[/php]
更多php相关知识,请访问!
以上就是php发送邮件:如何自定义reply-to头部以及附件的详细内容。
