请问,用PHP怎样发送HTML格式且带图片的邮件? java知道怎么做。替换image的src为tid:src?然后图片用作附件发送。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你个ZEND里面的函数吧!直接用这个函数即可function sendmail ($from_name, $from_email, $to_name, $to_email, $subject, $text_message="", $html_message, $attachment="") { $from = "$from_name <$from_email>"; $to = "$to_name <$to_email>"; $main_boundary = "----=_NextPart_".md5(rand()); $text_boundary = "----=_NextPart_".md5(rand()); $html_boundary = "----=_NextPart_".md5(rand()); $headers = "From: $from\n"; $headers .= "Reply-To: $from\n"; $headers .= "X-Mailer: ZEND (http://www.zend.com/)\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed;\n\tboundary=\"$main_boundary\"\n"; $message .= "\n--$main_boundary\n"; $message .= "Content-Type: multipart/alternative;\n\tboundary=\"$text_boundary\"\n"; $message .= "\n--$text_boundary\n"; $message .= "Content-Type: text/plain; charset=\"gb2312\"\n"; $message .= "Content-Transfer-Encoding: 7bit\n\n"; $message .= ($text_message!="")?"$text_message":"Text portion of HTML Email"; $message .= "\n--$text_boundary\n"; $message .= "Content-Type: multipart/related;\n\tboundary=\"$html_boundary\"\n"; $message .= "\n--$html_boundary\n"; $message .= "Content-Type: text/html; charset=\"gb2312\"\n"; $message .= "Content-Transfer-Encoding: quoted-printable\n\n"; $message .= str_replace ("=", "=3D", $html_message)."\n"; if (isset ($attachment) && $attachment != "" && count ($attachment) >= 1) { for ($i=0; $i<count ($attachment); $i++) { $attfile = $attachment[$i]; $file_name = basename ($attfile); $fp = fopen ($attfile, "r"); $fcontent = ""; while (!feof ($fp)) { $fcontent .= fgets ($fp, 1024); } $fcontent = chunk_split (base64_encode($fcontent)); @fclose ($fp); $message .= "\n--$html_boundary\n"; $message .= "Content-Type: application/octetstream\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: inline; filename=\"$file_name\"\n"; $message .= "Content-ID: <$file_name>\n\n"; $message .= $fcontent; } } $message .= "\n--$html_boundary--\n"; $message .= "\n--$text_boundary--\n"; $message .= "\n--$main_boundary--\n"; @mail ($to, $subject, $message, $headers); } php rewriterule 媳妇考试题(PHP),头想破了也没想出来,求高手解决。加分。!!! 谁帮我解释一下这段话是什么意思啊 用php处理数据,如何遍历一个mysql表? PHP程序连接SQL中的一个表其中包含有(时间戳),想导出时把时间戳还原如何做? 如何做个修改表单的按钮 靠!刚才发了个帖子,不知道跑到哪里了?? fsockopen()函数问题 php for win能调用自己写的dll吗? 无法正常上传图片到服务器 有点累,但挺有乐子--散分 PHP面向对象开发
function sendmail ($from_name, $from_email, $to_name, $to_email, $subject, $text_message="", $html_message, $attachment="")
{
$from = "$from_name <$from_email>";
$to = "$to_name <$to_email>";
$main_boundary = "----=_NextPart_".md5(rand());
$text_boundary = "----=_NextPart_".md5(rand());
$html_boundary = "----=_NextPart_".md5(rand());
$headers = "From: $from\n";
$headers .= "Reply-To: $from\n";
$headers .= "X-Mailer: ZEND (http://www.zend.com/)\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n\tboundary=\"$main_boundary\"\n";
$message .= "\n--$main_boundary\n";
$message .= "Content-Type: multipart/alternative;\n\tboundary=\"$text_boundary\"\n";
$message .= "\n--$text_boundary\n";
$message .= "Content-Type: text/plain; charset=\"gb2312\"\n";
$message .= "Content-Transfer-Encoding: 7bit\n\n";
$message .= ($text_message!="")?"$text_message":"Text portion of HTML Email";
$message .= "\n--$text_boundary\n";
$message .= "Content-Type: multipart/related;\n\tboundary=\"$html_boundary\"\n";
$message .= "\n--$html_boundary\n";
$message .= "Content-Type: text/html; charset=\"gb2312\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n\n";
$message .= str_replace ("=", "=3D", $html_message)."\n";
if (isset ($attachment) && $attachment != "" && count ($attachment) >= 1)
{
for ($i=0; $i<count ($attachment); $i++)
{
$attfile = $attachment[$i];
$file_name = basename ($attfile);
$fp = fopen ($attfile, "r");
$fcontent = "";
while (!feof ($fp))
{
$fcontent .= fgets ($fp, 1024);
}
$fcontent = chunk_split (base64_encode($fcontent));
@fclose ($fp);
$message .= "\n--$html_boundary\n";
$message .= "Content-Type: application/octetstream\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: inline; filename=\"$file_name\"\n";
$message .= "Content-ID: <$file_name>\n\n";
$message .= $fcontent;
}
}
$message .= "\n--$html_boundary--\n";
$message .= "\n--$text_boundary--\n";
$message .= "\n--$main_boundary--\n";
@mail ($to, $subject, $message, $headers);
}