使用phpmailer smtp发送邮件的最快方法? [英] fastest way to send mails using phpmailer smtp?

查看:144
本文介绍了使用phpmailer smtp发送邮件的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下phpmailer函数发送1000多封邮件

 <?php 
function sendMail sendTo,$ Subject,$ Body){

require_once'PHPMailer / PHPMailerAutoload.php';

$ mail = new PHPMailer;
$ mail-> isSMTP();
$ mail-> Host ='smtp.example.com; smtp.example.com';
$ mail-> SMTPAuth = true;
$ mail-> Username ='newsletter@example.com';
$ mail-> Password ='password';
$ mail-> SMTPSecure ='ssl';
$ mail-> Port = 465;
$ mail-> From ='newsletter@example.com';
$ mail-> FromName ='xyz';
$ mail-> WordWrap = 50;
$ mail-> isHTML(true);

$ mail-> addAddress($ sendTo);
$ mail-> Subject = $ Subject;
$ mail-> Body =(stripslashes($ Body));
$ mail-> AltBody ='请使用Html电子邮件客户端查看此消息!!';

if(!$ mail-> send()){
$ return ='无法发送消息。
// echo'Mailer Error:'。 $ MAIL-> ERRORINFO;
} else {
$ return ='消息已发送!
}
return $ return;
}

这是我用来调用函数的代码

  foreach($ emails as $ email){
$ subject =sample subject;
$ body =sample body;
sendMail($ email,$ subject,$ body);
}

$ emails数组的大小是1000+
有更快你应该从

/ PHPMailer / wiki /发送到列表rel =noreferrer>阅读PHPMailer提供的文档,您将在其中找到此示例



其中特别要注意的是,请确保使用 SMTPKeepAlive - 您可能会按照域名对列表进行排序,以最大限度地提高连接重新使用。



正如zerkms所说,您应该提交到本地邮件服务器以获得最佳性能,尽管令人惊讶地使用PHPMailer中的邮件 sendmail 选项并不总是比SMTP快到本地主机,主要是因为postfix'sendmail二进制打开与本地主机的同步SMTP连接 - postfix'docs re如果您要发送到本地主机,请不要使用验证或加密,因为开销并不会让您获得任何收益,但是如果您使用远程服务器,请使用端口587上的tls,而不是端口465上过时的ssl。



一般直接发送给最终用户应避免使用 - PHPMailer中的SMTP客户端有些笨拙 - 它根本不处理排队,因此任何具有灰名单或交付延迟的域都将无法传送。最好的方法是使用SMTP到附近的MTA,并将队列处理留给它。您也可以从中恢复弹跳,因此您可以从列表中删除不良地址。


i am using following phpmailer function to send 1000+ mails

<?php
function sendMail($sendTo,$Subject,$Body){

    require_once 'PHPMailer/PHPMailerAutoload.php';

    $mail = new PHPMailer;
    $mail->isSMTP();                                      
    $mail->Host = 'smtp.example.com;smtp.example.com';  
    $mail->SMTPAuth = true;                               
    $mail->Username = 'newsletter@example.com';           
    $mail->Password = 'password';                         
    $mail->SMTPSecure = 'ssl';                            
    $mail->Port = 465;                                    
    $mail->From = 'newsletter@example.com';
    $mail->FromName = 'xyz';
    $mail->WordWrap = 50;                                 
    $mail->isHTML(true);                                  

    $mail->addAddress($sendTo);               
    $mail->Subject = $Subject;
    $mail->Body = ( stripslashes( $Body ) );
    $mail->AltBody = 'Please Use a Html email Client To view This Message!!';

    if(!$mail->send()) {
        $return = 'Message could not be sent.';
        // echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        $return = 'Message has been sent!';
    }
    return $return;
}

and this is the code i am using to call function

foreach ($emails as $email) {
 $subject = "sample subject";
 $body = "sample body";
 sendMail($email, $subject, $body);
}

size of $emails array is 1000+ is there any faster and better way to do this?

解决方案

You should start by reading the docs provided with PHPMailer where you will find this example.

Of particular note in there, make sure you use SMTPKeepAlive - you may find benefit in sorting your list by domain to maximise connection re-use.

As zerkms said, you should submit to a local mail server for best performance, though surprisingly using mail or sendmail options in PHPMailer is not always faster than SMTP to localhost, largely because postfix' sendmail binary opens a synchronous SMTP connection to localhost anyway - postfix' docs recommend SMTP to localhost for best performance for this reason.

If you are sending to localhost, don't use auth or encryption as the overhead doesn't gain you anything, but if you are using a remote server, use tls on port 587 in preference to the obsolete ssl on port 465.

Generally sending directly to end users is to be avoided - the SMTP client in PHPMailer is somewhat dumb - it does not handle queuing at all, so any domains with greylisting or delivery deferrals for traffic control will fail to be delivered. the best approach is to use SMTP to a nearby MTA and leave the queue handling to that. You can get bounces back from that as well so you can remove bad addresses from your list.

这篇关于使用phpmailer smtp发送邮件的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆