dop83362 2012-08-29 12:48
浏览 44
已采纳

SwiftMailer Batch电子邮件将我的服务器运行时间

I realise that batchEmail is no longer part of the new SwiftMailer. So I made this script:

<?
//
// GC PRESS EMAILER v5
//
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once("config.php");
include_once("hawkmail/mail/lib/swift_required.php");
$c=mysql_connect($dbh,$dbu,$dbp);
function SendEmail(){
    // DB
    $s=mysql_query("SELECT * FROM `newgc`.`press_list`");
    // Process Color Listing Loop
    while($r=mysql_fetch_array($s)){
    // ###########################
    // START LOOP
    // ###########################
        $name=$r['name'];
        $email=$r['email'];
        $to=array(''.$email.''=>''.$name.'');
        include("hawkmail/templates/press.php");
        # Email subject
        $str=$name;
        $str=substr($str, 0, strrpos($str, ' '));
        $subject='Dear '.$str.', you are invited to our Exclusive Party Collection Press Day!';
        # send message
        include("hawkmail/settings.php");       
    }
    // ###########################
    // END LOOP
    // ###########################
}
SendEmail();
?>

The database has 200 records. And I ran the script and it sends a few emails and then times out

504 Gateway Time-out

The name and email records are like

John Smith John.smith@site.com

Very plain. And my hawkmail/settings.php is this:

# mail
$smpturl="smtp.sendgrid.net";
$mailu="sitesitesite";
$mailp="sitessssssssssss";
$from=array("no-reply@site.com"=>"site.com");

# login credentials & setup Swift mailer parameters
$transport=Swift_SmtpTransport::newInstance($smpturl, 587);
$transport->setUsername($mailu);
$transport->setPassword($mailp);
$swift=Swift_Mailer::newInstance($transport);

# create a message (subject)
$message=new Swift_Message($subject);

# attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');

$message->setTo($to);
$message->addPart($text, 'text/plain');

# actually send the message
if($recipients=$swift->send($message, $failures)){}else{}

Is there anyway to increase the limit of PHP time out (I use Ubuntu and Nginx) or is there an alternative to BatchMail() really don't understand why it was removed.

Can someone post examples of Batch mail scripts using the new swiftmailer?

  • 写回答

1条回答 默认 最新

  • drkxgs9358 2012-09-01 18:34
    关注

    Sending emails is the most complicated thing to do online.

    It is the second most used service and the most abused.

    I built my own custom email platform for sending bulk emails.

    The timeout you experience is because of the Apache and PHP execution limits.

    You need to run it as a CLI application with set_time_limit (0);

    php /path/to/app/script.php something like this straight in the console.

    If you do not have SSH access then run it with shell_exec like this:

    shell_exec("php /path/to/app/script.php > /dev/null 2>/dev/null &");
    

    This will ensure that the script that calls it does not hang around till it finishes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么