用phpmailer类怎样发附件! 没有用过,你可以到phpe.net里面看看,那里面有好几个发送附件的例子,给你顶 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用用这个试使,我用得挺好的。<?php/*$to 目标$subject 主题$message 正文$from 发自$content_type 类型$attache 附件,文件名放在数组中*/$email = $_POST['email'];$email = trim("$email");$message = "hello";function mail2( $to, $subject, $message, $from, $content_type, $attache="") { if(!empty($from)) $head = "From: $from\n"; if(empty($content_type)) $content_type = "text/plain"; if(is_array($attache)) { $boundary = "===" . md5(uniqid("")) . "==="; $head .= "Mime-Version: 1.0\nContent-Type: multipart/mixed; boundary=\""; $head .= "$boundary\"\n\nThis is a multi-part message in MIME format.\n\n"; $head .= "--$boundary\n"; $head .= "Content-Type: $content_type\n"; $head .= "\n$message\n\n"; while(list($key, $val) = each($attache)) { $fd = fopen("$val", "r") or die("unable to open file $val"); $contents = chunk_split(base64_encode(fread($fd,filesize("$val")))); fclose($fd); $head .= "--$boundary\n"; $head .= "Content-Type: application/octet-stream; name=\"".basename($val); $head .= "\"\nContent-Transfer-Encoding: BASE64\n"; $head .= "Content-Disposition: attachment; filename=\"".basename($val); $head .= "\"\n\n" . $contents . "\n\n"; } $head .= "--" . $boundary . "--\n\n"; }else{ if(!empty($content_type)) { $head .= "Content-Type: $content_type\n"; $head .= "\n$message\n"; } } return mail($to,$subject,"",$head ); } mail2("$email","",$message,"","",array("a.doc"));?> <html><head> <title></title></head><body><?phprequire("class.phpmailer.php");require("class.smtp.php");$mail = new PHPMailer();$mail->IsHTML(false);$mail->IsSMTP(); // send via SMTP$mail->Host = "smtp.vip.sina.com"; // SMTP servers$mail->Port = "25";$mail->SMTPAuth = true; // turn on SMTP authentication//$mail->Username = ""; // SMTP username//$mail->Password = ""; // SMTP password$mail->AddAddress("[email protected]", "xxx");$mail->Subject = "Here is the subject";//if(!$mail->AddAttachment("d:/test.txt","test-1.txt"))if(!$mail->AddAttachment("./test.txt","test-1.txt")){ echo "Add attachment false";}if(!$mail->Send()){ echo "Message was not sent <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit;}echo "Message has been sent";?></body></html>以上代码测试成功注意1.test.txt和class.phpmailer.php等放在同一目录下2.SMTP username和SMTP password自己添加 php 上传图片问题? 怎么合并变量 asp.netMD5加密函数改成php 见鬼了,PHP.INI怎么修改都无效 Something went wrong - -32300 : transport error - HTTP status code was not 200 请教被GOOGLE搜索的问题 多表查询之后如何应用结果? 请教高手!时间的问题 windows + php为什么不认QUERYSTRING,是否需要修改php.ini,怎么修改!? php不是一种很好的角本语言是吗? 如何避免重复定义函数 这里有一个比较搞笑的贴子,呵呵,有兴趣看一下
<?php
/*
$to 目标
$subject 主题
$message 正文
$from 发自
$content_type 类型
$attache 附件,文件名放在数组中
*/
$email = $_POST['email'];
$email = trim("$email");$message = "hello";function mail2( $to, $subject, $message, $from, $content_type, $attache="") {
if(!empty($from)) $head = "From: $from\n";
if(empty($content_type)) $content_type = "text/plain"; if(is_array($attache)) {
$boundary = "===" . md5(uniqid("")) . "===";
$head .= "Mime-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"";
$head .= "$boundary\"\n\nThis is a multi-part message in MIME format.\n\n";
$head .= "--$boundary\n";
$head .= "Content-Type: $content_type\n";
$head .= "\n$message\n\n"; while(list($key, $val) = each($attache)) {
$fd = fopen("$val", "r") or die("unable to open file $val");
$contents = chunk_split(base64_encode(fread($fd,filesize("$val"))));
fclose($fd);
$head .= "--$boundary\n";
$head .= "Content-Type: application/octet-stream; name=\"".basename($val);
$head .= "\"\nContent-Transfer-Encoding: BASE64\n";
$head .= "Content-Disposition: attachment; filename=\"".basename($val);
$head .= "\"\n\n" . $contents . "\n\n";
}
$head .= "--" . $boundary . "--\n\n";
}else{
if(!empty($content_type)) {
$head .= "Content-Type: $content_type\n";
$head .= "\n$message\n";
}
}
return mail($to,$subject,"",$head );
} mail2("$email","",$message,"","",array("a.doc"));?>
<title></title>
</head><body><?phprequire("class.phpmailer.php");
require("class.smtp.php");$mail = new PHPMailer();$mail->IsHTML(false);$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp.vip.sina.com"; // SMTP servers
$mail->Port = "25";
$mail->SMTPAuth = true; // turn on SMTP authentication
//$mail->Username = ""; // SMTP username
//$mail->Password = ""; // SMTP password$mail->AddAddress("[email protected]", "xxx");$mail->Subject = "Here is the subject";//if(!$mail->AddAttachment("d:/test.txt","test-1.txt"))if(!$mail->AddAttachment("./test.txt","test-1.txt"))
{
echo "Add attachment false";
}if(!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}echo "Message has been sent";?></body></html>以上代码测试成功
注意
1.test.txt和class.phpmailer.php等放在同一目录下
2.SMTP username和SMTP password自己添加