SwiftMailer批量电子邮件次我的服务器出(SwiftMailer Batch email t

2019-07-31 05:51发布

我认识到,batchEmail是新SwiftMailer不再一部分。 所以我做了这个脚本:

<?
//
// 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();
?>

该数据库有200条记录。 我跑了剧本,并将其发送几封电子邮件,然后超时

504网关超时

nameemail记录都喜欢

约翰·史密斯John.smith@site.com

很朴实。 而我hawkmail/settings.php是这样的:

# 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{}

反正是有增加的PHP时间的限制了(我使用Ubuntu和Nginx的),或者是有没有BatchMail替代()真不明白为什么它已被删除。

使用新的swiftmailer有人可以张贴批量邮件脚本的例子吗?

Answer 1:

发送电子邮件是在网上做的最复杂的事情。

这是第二个最常用的服务和最被滥用。

我建立我自己的自定义的电子邮件平台发送大量电子邮件。

您遇到超时是因为Apache和PHP执行限制。

你需要运行它作为一个CLI应用程序set_time_limit (0);

php /path/to/app/script.php像这样直接在控制台中。

如果你没有SSH访问然后运行它shell_exec是这样的:

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

这将确保,直到它完成调用它的脚本不流连。



文章来源: SwiftMailer Batch email times my Server out