Index: sites/all/modules/zend/zend_mail/zend_mail.inc =================================================================== --- sites/all/modules/zend/zend_mail/zend_mail.inc (Revision 49) +++ sites/all/modules/zend/zend_mail/zend_mail.inc (Revision 667) @@ -3,40 +3,41 @@ /** * Uses Zend_Mail to send emails. */ -function drupal_mail_wrapper($message) { +function drupal_mail_wrapper($mailkey, $to, $subject, $body, $from=NULL, $headers=NULL) { zend_initialize('Zend_Mail'); - - $transport = NULL; if (variable_get('zend_mail_transport', NULL) == 'smtp') { - zend_initialize('Zend_Mail_Transport_Smtp'); - $host = variable_get('zend_mail_smtp_host', 'localhost'); - $port = variable_get('zend_mail_smtp_port', 25); - $config = array('port' => $port); - if (variable_get('zend_mail_smtp_encryption', 'none') != 'none') { - $config['ssl'] = variable_get('zend_mail_smtp_encryption', 'none'); + static $transport; + // we might as well keep the transport, if we send multiple emails + if (!isset($transport)) { + zend_initialize('Zend_Mail_Transport_Smtp'); + $host = variable_get('zend_mail_smtp_host', 'localhost'); + $port = variable_get('zend_mail_smtp_port', 25); + $config = array('port' => $port); + if (variable_get('zend_mail_smtp_encryption', 'none') != 'none') { + $config['ssl'] = variable_get('zend_mail_smtp_encryption', 'none'); + } + $transport = new Zend_Mail_Transport_Smtp($host, $config); } - $transport = new Zend_Mail_Transport_Smtp($host, $config); - $transport->connect(); + } else { + // this makes sure that zend_mail will just use the default, and we don't see any E_ALL stuff + $transport = NULL; } - $mail = new Zend_Mail(); - foreach ($message['headers'] as $header => $value) { + foreach ($headers as $header => $value) { if ($header != 'Return-Path' && $header != 'From') { $mail->addHeader($header, $value); } } - $mail->setBodyText($message['body']); - $mail->setFrom($message['from']); - $mail->addTo($message['to']); - $mail->setSubject($message['subject']); + $mail->setBodyText($body); + $mail->setFrom($from); + $mail->addTo($to); + $mail->setSubject($subject); try { - @$mail->send($transport); + $mail->send($transport); } catch (Zend_Mail_Transport_Exception $ex) { - // Do nothing + watchdog('zend_mail' ,'drupal_mail_wrapper - error (#'.$ex->getCode().') - '.$ex->getMessage(), WATCHDOG_ERROR); + return FALSE; } - if ($transport) { - $transport->disconnect(); - } return TRUE; }