大家好,我正在用PHP开发电子邮件系统,通过SMTP协议发送电子邮件,一切都很顺利,现在我可以发送消息而没有问题,我实际上有两个问题,我希望我会找到一个解决方案,1-我发送电子邮件给用户使用phpmailer库,但我不能控制和得到发送电子邮件的结果,因为我发送了大约10个电子邮件在一个SMTP连接。这是我的发送码
$mail = new PHPMailer;
$froms=$respu['froms'];
$mail->Timeout = 3600;
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $respu['server']; // Specify main and backup SMTP servers
$mail->SMTPAuth = $respu['authentication']; // Enable SMTP authentication
$mail->Username = $respu['username']; // SMTP username
$mail->Password = $respu['password']; // SMTP password
$mail->SMTPSecure = $respu['security']; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $respu['port']; // TCP port to connect to
$mail->SetFrom($respu['username'],$froms);
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->MsgHTML($message);
if(!$mail->Send()) {
//$errors=$mail->getSMTPInstance()->getError();
$date=date('Y-m-d h:i');
echo $msg= "Message Not Sent: to $to " . $mail->ErrorInfo;
$date=date('Y-m-d h:i');
$sql="insert into log (log_text,user_email,log_time,status)values ('$msg','$to','$date',0) ";
$this->query_return($sql);
exit();
} else {$date=date('Y-m-d h:i');
$sql="insert into log (log_text,user_email,log_time,status)values ( 'Message Sent Successfully ','$to','$date',1) ";
$this->query_return($sql);
}if(!$mail->Send())条件每次都返回true,即使电子邮件是错误的。它的工作原理是测试SMTP连接是否完成,我想知道用户是否收到了电子邮件。
我的第二个问题是,我有超过3000个邮件地址,我想同时向他们发送电子邮件,正在发生的事情是这个过程需要很长时间,我必须等待很长时间才能完成,我如何才能更快地完成它。
发布于 2019-06-24 15:23:22
要发送到列表,请使用the mailing list example provided with PHPMailer作为起点。另请阅读the wiki article about sending to lists。
为了获得最佳性能,您希望提交到本地或附近的邮件服务器,然后由该服务器负责后续的传递。有些消息可能无法传递,在这种情况下,您将需要依赖退回处理程序;当消息发送失败时,它将返回到Return-path地址,您可以通过设置PHPMailer中的Sender属性来控制该地址(默认情况下,它使用您的From地址)。请注意,作为发送者,您应该自己设置return-path标头;这是接收服务器的工作。
但是要注意:处理退回消息是非常不愉快的;因为退回消息在正常使用中是相当“不可见”的,这意味着它们的质量非常不稳定。例如,来自某些Microsoft Exchange服务器的退回邮件可能会忽略邮件退回的地址!您可以通过使用VERP addressing来帮助您识别原始收件人地址,甚至识别单个邮件,从而处理这种情况(以及配置不佳的邮件服务器的许多其他缺点)。无论您如何处理此问题,您都需要与您的邮件服务器保持良好的对话关系。使用外部服务来处理这样的发送并不一定更好,因为它们面临着完全相同的问题,尽管它们至少可以处理退回处理的大部分不愉快。
仅供参考,我运行的是https://smartmessages.net,一个电子邮件营销服务;它是围绕PHPMailer构建的(这也是我是维护者的部分原因),我们可以以每秒300条消息的速度发送消息(使用非常好的邮件服务器),所以使用PHPMailer完全可以实现良好的吞吐量。
https://stackoverflow.com/questions/56730896
复制相似问题