各个电子邮件的PHPMailer设置正在发送空的To:字段
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了各个电子邮件的PHPMailer设置正在发送空的To:字段,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3275字,纯文字阅读大概需要5分钟。
内容图文
![各个电子邮件的PHPMailer设置正在发送空的To:字段](/upload/InfoBanner/zyjiaocheng/730/1665fb293d364f95886f1abfa5711f61.jpg)
使用PHPMailer向收件人发送个人电子邮件当我添加$mail-> SingleTo = TRUE时,我在To:字段中什么也没有收到;到我的代码.
当我删除$mail-> SingleTo = TRUE时;我在“收件人:”字段中收到的电子邮件地址是正确的.
这就是我得到的:
reply-to xxxxxx <xxxx@xxxx.com>, No Reply <no-reply@no-reply.com>
to
date Mon, Mar 21, 2011 at 5:07 PM
subject Testing
mailed-by gmail.com
signed-by gmail.com
(其中xxxxxxx代表我的电子邮件地址.)
这是我的代码:
if(isset($_POST['submit']))
{
require_once('PHPMailer_v5.1/class.phpmailer.php');
$mail = new PHPMailer();
$subject = $_POST['subject'];
$body = $_POST['emailbody'];
$to = $_POST['to'];
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "localhost"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "SSL"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "xxxxxxxxxx@gmail.com"; // GMAIL username
$mail->Password = "*********"; // GMAIL password
$mail->SetFrom('xxx@xxx.com', 'XXXXXX');
$mail->AddReplyTo("no-reply@xxxxx.com","No Reply");
$mail->Subject = $subject;
// After adding this line I'm getting an empty To: field
$mail->SingleTo = TRUE;
$mail->AddAddress("address1@xxxxxx.com", 'xyz abc');
$mail->AddAddress("address2@xxxxxx.com", 'abc xyz');
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
if(!$mail->Send()) {
$message= "Mailer Error: " . $mail->ErrorInfo;
}
else
{
$message= "Message sent!";
}
}
解决方法:
您正在使用SMTP发送电子邮件.使用Smtp发送时,phpmailer类没有使用SingleTo参数.
更多,如果你在SingleTo == true时看到CreateHeader函数,那么配方只能用于$this-> SingleToArray而不是标题本身,所以基本上它就是PHPmailer的bug.
看起来唯一的选择,除非你想修补phpmailer,就是在不使用SingleTo属性的情况下逐个发送电子邮件
解决方案将是
function & prepare_mailer($subject, $body) {
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "localhost"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "SSL"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "xxxxxxxxxx@gmail.com"; // GMAIL username
$mail->Password = "*********"; // GMAIL password
$mail->SetFrom('xxx@xxx.com', 'XXXXXX');
$mail->AddReplyTo("no-reply@xxxxx.com","No Reply");
$mail->Subject = $subject;
$mail->MsgHTML($body);
return $mail;
}
foreach( $_POST['to'] as $to ){
$mail = null;
$mail = & prepare_mailer($_POST['subject'],$_POST['body']);
$mail->AddAddress($to['address'], $to['name']);
$mail->Send();
}
内容总结
以上是互联网集市为您收集整理的各个电子邮件的PHPMailer设置正在发送空的To:字段全部内容,希望文章能够帮你解决各个电子邮件的PHPMailer设置正在发送空的To:字段所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。