您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2025/7/3 10:45:26发布19次查看
虽然有现成的类库(如pear)可以很方便地实现附件添加和发送,但是对于一些小站点(服务器硬件、网站规模都不理想),安装pear可能会带来不必要的负担,降低web程序运行效率。
通过对邮件格式的认识,我们可以写一个脚本来发送附件。代码并不长:
[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头部以及附件的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product