php中直接用mail函数发邮件,因为数量比较多,常常导致服务器出现很多sendmail进程,最后直接502 Bad Gateway
。  请问怎么解决这种发邮件问题呢?

解决方案 »

  1.   

    用smtp的类啊,网上很多的例子
      

  2.   

    function sendmail($setEmail, $setName, $body, $subject) {
    require_once("PHPMail/phpmailer.php");
    $mail = new PHPMailer ( true ); // the true param means it will throw exceptions on errors, which we need to catch
    $mail->IsSMTP (); // telling the class to use SMTP
    try {
    $mail->SMTPAuth = true; // enable SMTP authentication
    $mail->SMTPSecure = SBT_SSL; // sets the prefix to the servier
    $mail->Host = SBT_SMTP_HOST; // sets GMAIL as the SMTP server
    $mail->Port = SBT_SMTP_PORT; // set the SMTP port for the GMAIL server
    $mail->Username = SBT_SMTP_USER; // GMAIL username
    $mail->Password = SBT_SMTP_PASS; // GMAIL password
    $mail->AddReplyTo ( SBT_MAIL_FROM, SBT_MAIL_FROM_NAME );
    $mail->AddAddress ( $setEmail, $setName );
    $mail->SetFrom (SBT_SMTP_USER,SBT_SMTP_USER); //sender name
    $mail->Subject = $subject;
    $mail->MsgHTML ( $body );
    if (! $mail->Send ()) {
    echo "Message could not be sent. <p>";
    echo "Mailer Error: " . $mail->ErrorInfo;
    exit ();

    } catch ( phpmailerException $e ) {
    echo $e->errorMessage (); //Pretty error messages from PHPMailer
    } catch ( Exception $e ) {
    echo $e->getMessage (); //Boring error messages from anything else!
    }
      

  3.   

     smtp 用的不是别人的服务器吗?比如smtp.qq.com,这样每天会有发送限制的吧。
      

  4.   

    有可能是缺少主题,接受email格式错误等,最好是用Log把发送日志记录下来,这样就方便差错了
      

  5.   

    用别人的服务器有限制,确实这样。
    但人家的服务器是专业的邮件服务器,稳定啊。
    你的服务器sendmail,别说上千任务了,几百个就卡了。
    怎么办?说一说 我的无耻的办法。申请了100个126的号(实际远远不止100个,机器申请嘛,具体多少我就不说了)。
    做成数组,每次发邮件rand其中一个。如果126限制每个号一天200个邮件,那么100个号
    就可以发2w个邮件。而且phpmailer类,可以抄送,一次可以发50封。 嘿嘿 还行吧
      

  6.   

    用 sendmail发 服务器真的有可能受不了的 我以前用这个发的时候 发很几万封 服务器就负载比较高了后来用 exim 这个发信  好一些
    smtp 发信速度有点慢,但是基本上很少有延时,用sendmail 发信 经常今天发的信  明天或后天才收到。看自己情况吧 如果 邮件不多 就照上面那位老兄的办法 申请个100来个 126邮箱 随机发 ,不过这个弊端就是,不能设置自己的发件人,发出的邮件的发件人都是126的,没法带自己公司域名后缀用系统的发 就可以设置发件人,可以写成自己公司的邮箱,客户看起来舒服些。