PHP发送邮件:如何自定义reply-to头部以及附件-php教程

资源魔 84 0
9.jpg

尽管有现成的类库(如PEAR)能够很不便地完成附件增加以及发送,然而关于一些小站点(效劳器硬件、网站规模都不睬想),装置PEAR可能会带来不用要的累赘,升高WEB顺序运转效率。

经过对邮件格局的意识,咱们能够写一个剧本来发送附件。代码其实不长:

[php]

function mailSend($to, $subject, $message, $attach, $from, $replyto) {
//界说鸿沟线
$boundary = uniqid();
//天生邮件头
$header = "From: $from
Reply-to:$replyto
Content-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 = "
–$boundary
Content-type: text/plain; charset=utf-8;
Content-transfer-encoding: 8bit
$message
–$boundary
Content-Type: $mimeType; name=$attach
Content-Disposition: attachment; filename=$attach
Content-Transfer-Encoding: base64
$content
–$boundary–";
//发送邮件
mail($to, $subject, $body, $header) or die("Failed to send mail…");
}

[/php]

更多PHP相干常识,请拜访PHP中文网!

以上就是PHP发送邮件:若何自界说reply-to头部和附件的具体内容,更多请存眷资源魔其它相干文章!

标签: php开发教程 php开发资料 php开发自学 邮件

抱歉,评论功能暂时关闭!