关于PHPMailer下载,可在以下链接下载:
http://sourceforge.net/projects/phpmailer/
以下是我写的一个测试方法,支持多附件,多用户抄送。
<?php require("class.phpmailer.php"); function smtp_send_mail($sendto_email, $subject, $body, $add_cc = '',$attachment = '') { $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->Host = "smtp.exmail.qq.com"; // SMTP servers $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "admin@xxxx.com"; // SMTP username 注意:普通邮件认证不需要加 @域名 $mail->Password = "********"; // SMTP password $mail->From = "admin@xxxx.com"; // 发件人邮箱 $mail->FromName = "测试"; // 发件人 $mail->CharSet = "UTF-8"; // 这里指定字符集! $mail->Encoding = "base64"; $mail->AddAddress($sendto_email, $sendto_email); // 收件人邮箱和姓名 $index = explode(",",$add_cc); for($cc=0;$cc<count($index);$cc++){ $mail->AddCC($index[$cc],$index[$cc]); } //$mail->AddReplyTo("admin@hifyl.com", "hifyl.com"); //$mail->WordWrap = 50; // set word wrap 换行字数 $att = explode(",",$attachment); for($index=0;$index<count($att);$index++){ $mail->AddAttachment($att[$index], $att[$index]); } $mail->IsHTML(true); // send as HTML // 邮件主题 $mail->Subject = $subject; // 邮件内容 $mail->Body = $body; $mail->AltBody = "text/html"; if (!$mail->Send()) { echo "邮件发送有误 \n"; echo "邮件错误信息: " . $mail->ErrorInfo . "\n"; exit; } else { echo "邮件发送成功! \n"; } } $att = 'ip.txt'; //这里可以以,分隔添加多个附件,注意附件路径 $cc_email='qin49@126.com,123456@qq.com'; $content = file_get_contents('ip.txt'); smtp_send_mail("411239339@qq.com", "测试邮件抄送", "测试邮件抄送" . $content, $cc_email, $att); ?>