views:

42

answers:

4

i am trying to send something like news letter Via Zend_Mail but after 12 mail i got this message

Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files\Zend\Apache2\htdocs\forga\library\Zend\Mail\Protocol\Abstract.php on line 321

my Code is like:

$smtpHost = 'smtp.gmail.com';

$smtpConf = array(
        'auth' => 'login',
        'ssl' => 'tls',
        'port' => '587',
        'username' =>'[email protected]',
        'password' => 'xxxxxxxx'
        );    
$transport = new Zend_Mail_Transport_Smtp($smtpHost, $smtpConf);

foreach($users as $user)
{
    $mail = new Zend_Mail();
    $mail->setFrom("[email protected]", 'Forga');
    $mail->setSubject($subject);
    if($html=='on')
        $mail->setBodyHtml($message);
    else
        $mail->setBodyText($message);
    $mail->addto($user);
    $transport->send($mail);
}
+1  A: 

From the script timeout you get I'd assume your host is slow to send eMails and simply cannot handle bulk sending of eMails. You could increase the time until a script times out with

A more elegant way would be to send the eMails in separate processes asynchronously. Check out

Part 3 deals with eMails specifically.

Gordon
A: 

Check out my answer on another posting on parallel processing in PHP Multithreading/Parallel Processing in PHP. I think it's relevant. If you need something to be done outside of the individual request it should probably be passed to some kind of queue.

Kevin Schroeder
A: 

Do you manage the web server yourself?
Up to version 5.3.0, set_time_limit() only works in safe mode. (deprecated in recent PHP).
You can set safe mode in php.ini.

See also max_execution_time in php.ini.

MattBianco
A: 

By the looks of your code your sending a single email to each on individually from your server.. Try doing the following.

$smtpHost = 'smtp.gmail.com';

$smtpConf = array(
        'auth' => 'login',
        'ssl' => 'tls',
        'port' => '587',
        'username' =>'[email protected]',
        'password' => 'xxxxxxxx'
        );    
$transport = new Zend_Mail_Transport_Smtp($smtpHost, $smtpConf);
$mail = new Zend_Mail();
$mail->setFrom("[email protected]", 'Forga');
$mail->setSubject($subject);
$html=='on' ?$mail->setBodyHtml($message) : $mail->setBodyText($message);

foreach($users as $user)
{
    $mail->addto($user);
}

$transport->send($mail);

No i might actually be wrong with this because the other email addresses may be visible to all recipients, im not sure if that's only the concerning section of the email.

Regards

RobertPitt