本文整理汇总了PHP中Zend_Mail::setReturnPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Mail::setReturnPath方法的具体用法?PHP Zend_Mail::setReturnPath怎么用?PHP Zend_Mail::setReturnPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Mail
的用法示例。
在下文中一共展示了Zend_Mail::setReturnPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _sendEmail
protected function _sendEmail(array $email, array $user, Zend_Mail_Transport_Abstract $transport)
{
if (!$user['email']) {
return;
}
$phraseTitles = XenForo_Helper_String::findPhraseNamesFromStringSimple($email['email_title'] . $email['email_body']);
/** @var XenForo_Model_Phrase $phraseModel */
$phraseModel = XenForo_Model::create('XenForo_Model_Phrase');
$phrases = $phraseModel->getPhraseTextFromPhraseTitles($phraseTitles, $user['language_id']);
foreach ($phraseTitles as $search => $phraseTitle) {
if (isset($phrases[$phraseTitle])) {
$email['email_title'] = str_replace($search, $phrases[$phraseTitle], $email['email_title']);
$email['email_body'] = str_replace($search, $phrases[$phraseTitle], $email['email_body']);
}
}
$mailObj = new Zend_Mail('utf-8');
$mailObj->setSubject($email['email_title'])->addTo($user['email'], $user['username'])->setFrom($email['from_email'], $email['from_name']);
$options = XenForo_Application::getOptions();
$bounceEmailAddress = $options->bounceEmailAddress;
if (!$bounceEmailAddress) {
$bounceEmailAddress = $options->defaultEmailAddress;
}
$toEmail = $user['email'];
$bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
$mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
if ($options->enableVerp) {
$verpValue = str_replace('@', '=', $toEmail);
$bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
}
$mailObj->setReturnPath($bounceEmailAddress);
if ($email['email_format'] == 'html') {
$replacements = array('{name}' => htmlspecialchars($user['username']), '{email}' => htmlspecialchars($user['email']), '{id}' => $user['user_id']);
$email['email_body'] = strtr($email['email_body'], $replacements);
$text = trim(htmlspecialchars_decode(strip_tags($email['email_body'])));
$mailObj->setBodyHtml($email['email_body'])->setBodyText($text);
} else {
$replacements = array('{name}' => $user['username'], '{email}' => $user['email'], '{id}' => $user['user_id']);
$email['email_body'] = strtr($email['email_body'], $replacements);
$mailObj->setBodyText($email['email_body']);
}
if (!$mailObj->getMessageId()) {
$mailObj->setMessageId();
}
$thisTransport = XenForo_Mail::getFinalTransportForMail($mailObj, $transport);
try {
$mailObj->send($thisTransport);
} catch (Exception $e) {
if (method_exists($thisTransport, 'resetConnection')) {
XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
$thisTransport->resetConnection();
try {
$mailObj->send($thisTransport);
} catch (Exception $e) {
XenForo_Error::logException($e, false, "Email to {$user['email']} failed (after retry): ");
}
} else {
XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
}
}
}
示例2: send
/**
* Send all messages in a queue
*
* @return Mage_Core_Model_Email_Queue
*/
public function send()
{
/** @var $collection Mage_Core_Model_Resource_Email_Queue_Collection */
$collection = Mage::getModel('core/email_queue')->getCollection()->addOnlyForSendingFilter()->setPageSize(self::MESSAGES_LIMIT_PER_CRON_RUN)->setCurPage(1)->load();
ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
/** @var $message Mage_Core_Model_Email_Queue */
foreach ($collection as $message) {
if ($message->getId()) {
$parameters = new Varien_Object($message->getMessageParameters());
if ($parameters->getReturnPathEmail() !== null) {
$mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $parameters->getReturnPathEmail());
Zend_Mail::setDefaultTransport($mailTransport);
}
$mailer = new Zend_Mail('utf-8');
foreach ($message->getRecipients() as $recipient) {
list($email, $name, $type) = $recipient;
switch ($type) {
case self::EMAIL_TYPE_BCC:
$mailer->addBcc($email, '=?utf-8?B?' . base64_encode($name) . '?=');
break;
case self::EMAIL_TYPE_TO:
case self::EMAIL_TYPE_CC:
default:
$mailer->addTo($email, '=?utf-8?B?' . base64_encode($name) . '?=');
break;
}
}
if ($parameters->getIsPlain()) {
$mailer->setBodyText($message->getMessageBody());
} else {
$mailer->setBodyHTML($message->getMessageBody());
}
$mailer->setSubject('=?utf-8?B?' . base64_encode($parameters->getSubject()) . '?=');
$mailer->setFrom($parameters->getFromEmail(), $parameters->getFromName());
if ($parameters->getReplyTo() !== null) {
$mailer->setReplyTo($parameters->getReplyTo());
}
if ($parameters->getReturnTo() !== null) {
$mailer->setReturnPath($parameters->getReturnTo());
}
try {
//$mailer->send();
$mailer->send(Mage::helper('smtp')->getTransport());
unset($mailer);
$message->setProcessedAt(Varien_Date::formatDate(true));
$message->save();
} catch (Exception $e) {
unset($mailer);
$oldDevMode = Mage::getIsDeveloperMode();
Mage::setIsDeveloperMode(true);
Mage::logException($e);
Mage::setIsDeveloperMode($oldDevMode);
return false;
}
}
}
return $this;
}
示例3: send
public static function send($email, $name, $subject, $view, $data, $containerViewFile = 'mail')
{
self::init();
if (is_object($data)) {
$data->email = $email;
$data->subject = $subject;
} else {
if (is_array($data)) {
$data['email'] = $email;
$data['subject'] = $subject;
} else {
$data = array();
$data['email'] = $email;
$data['subject'] = $subject;
}
}
if (Settings::get(Settings::DEBUG, false) && Settings::get(self::TEST_MAIL, '') != '') {
$email = Settings::get(self::TEST_MAIL, '');
}
$html = self::preview($view, $data, $containerViewFile, false);
$text = trim(self::preview($view, $data, $containerViewFile, true));
if (String::isHtml($text) || $text == '') {
$text = T("This is an HTML message. Please use a HTML capable mail program to read this message.");
}
$mail = new Zend_Mail(Settings::get(Settings::ENCODING));
$fromName = Settings::get(self::FROM_NAME);
$fromMail = Settings::get(self::FROM_MAIL);
$mail->setFrom($fromMail, $fromName);
$mail->setReplyTo(Settings::get(self::REPLY_MAIL, $fromMail), $fromName);
$mail->setReturnPath(Settings::get(self::RETURN_MAIL, $fromMail), $fromName);
$mail->setSubject($subject);
$mail->setBodyHtml($html);
$mail->addTo($email, $name);
$mail->setBodyText($text);
if (Settings::get(self::SELF_EMAIL, false)) {
$mail->addBcc(Settings::get(self::SELF_EMAIL));
}
$mail->send();
}
示例4: sendAdminMail
/**
* Функция настроена для отправки сообщений через mail.russ-call.ru
* ИСПРАВЛЯТЬ ОСТОРОЖНО! Может не доставляться почта или сообщения
* пойдут в спам
*
* @param Forum_Model_Forum $post
* @return $this
*/
public function sendAdminMail(Forum_Model_Forum $post)
{
$mailToAdmin = new Zend_Mail("utf-8");
//$mailToAdmin->setFrom($post->getEmail(), $post->getAuthor());
$mailToAdmin->setFrom("info@alpha-hydro.com", "Alpha-Hydro");
$mailToAdmin->setSubject("Alpha-Hydro.Forum.");
$mailToAdmin->setReturnPath("info@alpha-hydro.com");
$textHtml = '<p>Автор: ' . $post->getAuthor() . ' (' . $post->getEmail() . ')</p>';
$textHtml .= '<p>Категория: ' . $post->getCategory() . '</p>';
$textHtml .= '<p><b>Сообщение:</b></p>';
$textHtml .= $post->getContent();
$mailToAdmin->setBodyHtml($textHtml);
//$mailToAdmin->addTo("admin@alpha-hydro.com", "Alpha-Hydro");
$mailToAdmin->addTo("info@alpha-hydro.com", "Alpha-Hydro");
$mailToAdmin->addBcc(array("fra@alpha-hydro.com", "kma@alpha-hydro.com", "admin@alpha-hydro.com"));
//$mailToAdmin->addBcc('mvl@alpha-hydro.com');
$mailToAdmin->send();
return $this;
}
示例5: execute
public static function execute($subject, $to, $from, $body)
{
if (!$to) {
return false;
}
self::initialize();
opApplicationConfiguration::registerZend();
$subject = mb_convert_kana($subject, 'KV');
$mailer = new Zend_Mail('iso-2022-jp');
$mailer->setHeaderEncoding(Zend_Mime::ENCODING_BASE64)->setFrom($from)->addTo($to)->setSubject(mb_encode_mimeheader($subject, 'iso-2022-jp'))->setBodyText(mb_convert_encoding($body, 'JIS', 'UTF-8'), 'iso-2022-jp', Zend_Mime::ENCODING_7BIT);
if ($envelopeFrom = sfConfig::get('op_mail_envelope_from')) {
$mailer->setReturnPath($envelopeFrom);
}
$result = $mailer->send();
Zend_Loader::registerAutoLoad('Zend_Loader', false);
return $result;
}
示例6: _sendEmail
protected function _sendEmail(array $user, array $email, Zend_Mail_Transport_Abstract $transport)
{
if (!$user['email']) {
return false;
}
if (!XenForo_Application::get('config')->enableMail) {
return true;
}
$options = XenForo_Application::getOptions();
XenForo_Db::ping();
$mailObj = new Zend_Mail('utf-8');
$mailObj->setSubject($email['email_title'])->addTo($user['email'], $user['username'])->setFrom($email['from_email'], $email['from_name']);
$bounceEmailAddress = $options->bounceEmailAddress;
if (!$bounceEmailAddress) {
$bounceEmailAddress = $options->defaultEmailAddress;
}
$toEmail = $user['email'];
$bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
$mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
if ($options->enableVerp) {
$verpValue = str_replace('@', '=', $toEmail);
$bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
}
$mailObj->setReturnPath($bounceEmailAddress);
if ($email['email_format'] == 'html') {
$replacements = array('{name}' => htmlspecialchars($user['username']), '{email}' => htmlspecialchars($user['email']), '{id}' => $user['user_id']);
$email['email_body'] = strtr($email['email_body'], $replacements);
$text = trim(htmlspecialchars_decode(strip_tags($email['email_body'])));
$mailObj->setBodyHtml($email['email_body'])->setBodyText($text);
} else {
$replacements = array('{name}' => $user['username'], '{email}' => $user['email'], '{id}' => $user['user_id']);
$email['email_body'] = strtr($email['email_body'], $replacements);
$mailObj->setBodyText($email['email_body']);
}
if (!$mailObj->getMessageId()) {
$mailObj->setMessageId();
}
$thisTransport = XenForo_Mail::getFinalTransportForMail($mailObj, $transport);
try {
$mailObj->send($thisTransport);
} catch (Exception $e) {
XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
return false;
}
return true;
}
示例7: getPreparedMailHandler
/**
* Gets the fully prepared, internal mail object. This can be called directly
* to allow advanced manipulation before sending
*
* @param string $toEmail The email address the email is sent to
* @param string $toName Name of the person receiving it
* @param array $headers List of additional headers to send
* @param string $fromEmail Email address the email should come from; if not specified, uses board default
* @param string $fromName Name the email should come from; if not specified, uses board default
* @param string $returnPath The return path of the email (where bounces should go to)
*
* @return Zend_Mail|false
*/
public function getPreparedMailHandler($toEmail, $toName = '', array $headers = array(), $fromEmail = '', $fromName = '', $returnPath = '')
{
if (!$toEmail) {
return false;
}
$contents = $this->prepareMailContents();
if (!$contents) {
return false;
}
$contents = $this->wrapMailContainer($contents['subject'], $contents['bodyText'], $contents['bodyHtml']);
$mailObj = new Zend_Mail('utf-8');
$mailObj->setSubject($contents['subject'])->setBodyText($contents['bodyText'])->addTo($toEmail, $toName);
if ($contents['bodyHtml'] !== '') {
$mailObj->setBodyHtml($contents['bodyHtml']);
}
$options = XenForo_Application::getOptions();
if (!$fromName) {
$fromName = $options->emailSenderName ? $options->emailSenderName : $options->boardTitle;
}
if ($fromEmail) {
$mailObj->setFrom($fromEmail, $fromName);
} else {
$mailObj->setFrom($options->defaultEmailAddress, $fromName);
}
if ($returnPath) {
$mailObj->setReturnPath($returnPath);
} else {
$bounceEmailAddress = $options->bounceEmailAddress;
if (!$bounceEmailAddress) {
$bounceEmailAddress = $options->defaultEmailAddress;
}
$bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
$mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
if ($options->enableVerp) {
$verpValue = str_replace('@', '=', $toEmail);
$bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
}
$mailObj->setReturnPath($bounceEmailAddress);
}
foreach ($headers as $headerName => $headerValue) {
if (isset(self::$_headerMap[strtolower($headerName)])) {
$func = self::$_headerMap[strtolower($headerName)];
$mailObj->{$func}($headerValue);
} else {
$mailObj->addHeader($headerName, $headerValue);
}
}
if (!$mailObj->getMessageId()) {
$mailObj->setMessageId();
}
return $mailObj;
}
示例8: setReturnPath
public function setReturnPath($email)
{
parent::clearReturnPath();
return parent::setReturnPath($email);
}
示例9: save
public function save()
{
$subject = $this->_options['email_subject_template']['option_value'];
$recipient = trim($this->_options['email_recipient_email']['option_value']);
if (strpos($recipient, ',') !== false) {
$recipient = explode(',', $recipient);
foreach ($recipient as &$recip) {
$recip = trim($recip);
}
}
$sender = trim($this->_options['email_sender_email']['option_value']);
$format = $this->_options['email_format']['option_value'];
// default to visitor's e-mail address, but stop execution for guests
if ($sender == '') {
if (!XenForo_Visitor::getUserId()) {
return false;
} else {
$sender = XenForo_Visitor::getInstance()->email;
}
}
if ($this->_options['email_message_template']['option_value'] == '') {
$message = '';
foreach ($this->_templateFields as $field) {
if ($this->_options['email_hide_empty_fields']['option_value'] == array() || $this->_options['email_hide_empty_fields']['option_value'] !== array() && $field['value'] != '') {
$message .= $field['title'] . ': ' . $field['value'] . PHP_EOL;
}
}
} else {
$message = $this->_options['email_message_template']['option_value'];
}
$transport = XenForo_Mail::getDefaultTransport();
$mailObj = new Zend_Mail('utf-8');
$mailObj->setSubject($subject)->addTo($recipient)->setFrom(XenForo_Application::getOptions()->defaultEmailAddress)->setReplyTo($sender);
if ($this->_attachmentHash) {
$attachmentModel = XenForo_Model::create('XenForo_Model_Attachment');
$attachments = $attachmentModel->getAttachmentsByTempHash($this->_attachmentHash);
foreach ($attachments as $attachmentId => $attachment) {
$attachmentData = $attachmentModel->getAttachmentDataById($attachment['data_id']);
$attachmentDataFile = $attachmentModel->getAttachmentDataFilePath($attachmentData);
$fileOutput = new XenForo_FileOutput($attachmentDataFile);
$mailAttachment = $mailObj->createAttachment($fileOutput->getContents());
$mailAttachment->filename = $attachmentData['filename'];
// delete the attachment as it is no longer needed
$dw = XenForo_DataWriter::create('XenForo_DataWriter_Attachment');
$dw->setExistingData($attachment);
$dw->delete();
}
}
$options = XenForo_Application::get('options');
$bounceEmailAddress = $options->bounceEmailAddress;
if (!$bounceEmailAddress) {
$bounceEmailAddress = $options->defaultEmailAddress;
}
$mailObj->setReturnPath($bounceEmailAddress);
// create plain text message
$bbCodeParserText = new XenForo_BbCode_Parser(XenForo_BbCode_Formatter_Base::create('Text'));
$messageText = new XenForo_BbCode_TextWrapper($message, $bbCodeParserText);
if ($format == 'html') {
// create html message
$bbCodeParserHtml = new XenForo_BbCode_Parser(XenForo_BbCode_Formatter_Base::create('HtmlEmail'));
$messageHtml = new XenForo_BbCode_TextWrapper($message, $bbCodeParserHtml);
$mailObj->setBodyHtml(htmlspecialchars_decode($messageHtml))->setBodyText($messageText);
} else {
$mailObj->setBodyText($messageText);
}
$mailObj->send($transport);
}
示例10: _sendConfirmEmail
protected function _sendConfirmEmail($emailAddress)
{
$confirm = new AccountConfirm();
$confirm->emailAddress = $emailAddress;
$confirm->save();
$this->view->layout()->setLayout('blank');
$this->view->assign('emailAddress', $confirm->emailAddress);
$this->view->assign('confirmCode', $confirm->code);
$link = $this->_helper->url('confirm', 'account', 'default', array('email' => $confirm->emailAddress, 'code' => $confirm->code));
$this->view->assign('link', "http://{$this->_config->hostname}/{$link}");
$mail = new Zend_Mail();
$mail->addTo($confirm->emailAddress);
$mail->setBodyText($this->view->render('mail/confirm-text.phtml'));
$mail->setBodyHtml($this->view->render('mail/confirm-html.phtml'));
$mail->setFrom('accounts@' . $this->_config->hostname, 'BitNotion, M.D.');
$mail->setReturnPath('no-reply@' . $this->_config->hostname);
$mail->setSubject('BitNotion | Please Confirm Your E-Mail Address');
$mail->send();
}
示例11: execute
public static function execute($subject, $to, $from, $body)
{
if (!$to) {
return false;
}
self::initialize();
opApplicationConfiguration::registerZend();
$subject = mb_convert_kana($subject, 'KV');
$mailer = new Zend_Mail('iso-2022-jp');
$mailer->setHeaderEncoding(Zend_Mime::ENCODING_BASE64)->setFrom($from)->addTo($to)->setSubject(mb_encode_mimeheader($subject, 'iso-2022-jp'))->setBodyText(mb_convert_encoding($body, 'JIS', 'UTF-8'), 'iso-2022-jp', Zend_Mime::ENCODING_7BIT);
if ($envelopeFrom = sfConfig::get('op_mail_envelope_from')) {
$mailer->setReturnPath($envelopeFrom);
}
try {
$result = $mailer->send();
} catch (Zend_Mail_Protocol_Exception $e) {
if (sfContext::getInstance()->getActionName() === null) {
error_log('Mail Send Error');
} else {
$action = sfContext::getInstance()->getActionStack()->getFirstEntry()->getActionInstance();
$action->redirect('default/mailError');
}
}
Zend_Loader::registerAutoLoad('Zend_Loader', false);
return $result;
}
示例12: testReturnPath
public function testReturnPath()
{
$mail = new Zend_Mail();
$res = $mail->setBodyText('This is a test.');
$mail->setFrom('testmail@example.com', 'test Mail User');
$mail->setSubject('My Subject');
$mail->addTo('recipient1@example.com');
$mail->addTo('recipient2@example.com');
$mail->addBcc('recipient1_bcc@example.com');
$mail->addBcc('recipient2_bcc@example.com');
$mail->addCc('recipient1_cc@example.com', 'Example no. 1 for cc');
$mail->addCc('recipient2_cc@example.com', 'Example no. 2 for cc');
// First example: from and return-path should be equal
$mock = new Zend_Mail_Transport_Mock();
$mail->send($mock);
$this->assertTrue($mock->called);
$this->assertEquals($mail->getFrom(), $mock->returnPath);
// Second example: from and return-path should not be equal
$mail->setReturnPath('sender2@example.com');
$mock = new Zend_Mail_Transport_Mock();
$mail->send($mock);
$this->assertTrue($mock->called);
$this->assertNotEquals($mail->getFrom(), $mock->returnPath);
$this->assertEquals($mail->getReturnPath(), $mock->returnPath);
$this->assertNotEquals($mock->returnPath, $mock->from);
}
示例13: _sendEmail
protected function _sendEmail(array $user, array $email, Zend_Mail_Transport_Abstract $transport)
{
if (!$user['email']) {
return false;
}
$mailObj = new Zend_Mail('utf-8');
$mailObj->setSubject($email['email_title'])->addTo($user['email'], $user['username'])->setFrom($email['from_email'], $email['from_name']);
$options = XenForo_Application::get('options');
$bounceEmailAddress = $options->bounceEmailAddress;
if (!$bounceEmailAddress) {
$bounceEmailAddress = $options->defaultEmailAddress;
}
$mailObj->setReturnPath($bounceEmailAddress);
if ($email['email_format'] == 'html') {
$replacements = array('{name}' => htmlspecialchars($user['username']), '{email}' => htmlspecialchars($user['email']), '{id}' => $user['user_id']);
$email['email_body'] = strtr($email['email_body'], $replacements);
$text = trim(htmlspecialchars_decode(strip_tags($email['email_body'])));
$mailObj->setBodyHtml($email['email_body'])->setBodyText($text);
} else {
$replacements = array('{name}' => $user['username'], '{email}' => $user['email'], '{id}' => $user['user_id']);
$email['email_body'] = strtr($email['email_body'], $replacements);
$mailObj->setBodyText($email['email_body']);
}
try {
$mailObj->send($transport);
} catch (Exception $e) {
return false;
}
return true;
}
示例14: execute
public function execute(array $deferred, array $data, $targetRunTime, &$status)
{
$data = array_merge(array('start' => 0, 'count' => 0, 'criteria' => null, 'userIds' => null, 'email' => array()), $data);
if (!XenForo_Application::get('config')->enableMail) {
return false;
}
$s = microtime(true);
/* @var $userModel XenForo_Model_User */
$userModel = XenForo_Model::create('XenForo_Model_User');
if (is_array($data['criteria'])) {
$userIds = $userModel->getUserIds($data['criteria'], $data['start'], 1000);
} else {
if (is_array($data['userIds'])) {
$userIds = $data['userIds'];
} else {
$userIds = array();
}
}
if (!$userIds) {
return false;
}
$options = XenForo_Application::getOptions();
$email = $data['email'];
$transport = XenForo_Mail::getTransport();
$limitTime = $targetRunTime > 0;
foreach ($userIds as $key => $userId) {
$data['count']++;
$data['start'] = $userId;
unset($userIds[$key]);
$user = $userModel->getUserById($userId);
if (!$user['email']) {
continue;
}
$phraseTitles = XenForo_Helper_String::findPhraseNamesFromStringSimple($email['email_title'] . $email['email_body']);
/** @var XenForo_Model_Phrase $phraseModel */
$phraseModel = XenForo_Model::create('XenForo_Model_Phrase');
$phrases = $phraseModel->getPhraseTextFromPhraseTitles($phraseTitles, $user['language_id']);
foreach ($phraseTitles as $search => $phraseTitle) {
if (isset($phrases[$phraseTitle])) {
$email['email_title'] = str_replace($search, $phrases[$phraseTitle], $email['email_title']);
$email['email_body'] = str_replace($search, $phrases[$phraseTitle], $email['email_body']);
}
}
$mailObj = new Zend_Mail('utf-8');
$mailObj->setSubject($email['email_title'])->addTo($user['email'], $user['username'])->setFrom($email['from_email'], $email['from_name']);
$bounceEmailAddress = $options->bounceEmailAddress;
if (!$bounceEmailAddress) {
$bounceEmailAddress = $options->defaultEmailAddress;
}
$toEmail = $user['email'];
$bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
$mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
if ($options->enableVerp) {
$verpValue = str_replace('@', '=', $toEmail);
$bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
}
$mailObj->setReturnPath($bounceEmailAddress);
if ($email['email_format'] == 'html') {
$replacements = array('{name}' => htmlspecialchars($user['username']), '{email}' => htmlspecialchars($user['email']), '{id}' => $user['user_id']);
$email['email_body'] = strtr($email['email_body'], $replacements);
$text = trim(htmlspecialchars_decode(strip_tags($email['email_body'])));
$mailObj->setBodyHtml($email['email_body'])->setBodyText($text);
} else {
$replacements = array('{name}' => $user['username'], '{email}' => $user['email'], '{id}' => $user['user_id']);
$email['email_body'] = strtr($email['email_body'], $replacements);
$mailObj->setBodyText($email['email_body']);
}
if (!$mailObj->getMessageId()) {
$mailObj->setMessageId();
}
$thisTransport = XenForo_Mail::getFinalTransportForMail($mailObj, $transport);
try {
$mailObj->send($thisTransport);
} catch (Exception $e) {
XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
continue;
}
if ($limitTime && microtime(true) - $s > $targetRunTime) {
break;
}
}
if (is_array($data['userIds'])) {
$data['userIds'] = $userIds;
}
$actionPhrase = new XenForo_Phrase('emailing');
$typePhrase = new XenForo_Phrase('users');
$status = sprintf('%s... %s (%d)', $actionPhrase, $typePhrase, $data['count']);
return $data;
}
示例15: send
public function send()
{
$_helper = Mage::helper('smtppro');
// if we have a valid queue page size override, use it
if (is_numeric($_helper->getQueuePerCron()) && intval($_helper->getQueuePerCron()) > 0) {
$percron = $_helper->getQueuePerCron();
$_helper->log('SMTP Pro using queue override page size: ' . $percron);
} else {
$percron = self::MESSAGES_LIMIT_PER_CRON_RUN;
}
$pauseMicros = 0;
// if we have a valid pause, use it
if (is_numeric($_helper->getQueuePause()) && intval($_helper->getQueuePause()) > 0) {
$pauseMicros = $_helper->getQueuePause() * 1000;
// * 1000 for millis => micros
$_helper->log('SMTP Pro using queue override pause: ' . $pauseMicros);
}
/** @var $collection Mage_Core_Model_Resource_Email_Queue_Collection */
$collection = Mage::getModel('core/email_queue')->getCollection()->addOnlyForSendingFilter()->setPageSize($percron)->setCurPage(1)->load();
ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
/** @var $message Mage_Core_Model_Email_Queue */
foreach ($collection as $message) {
if ($message->getId()) {
$parameters = new Varien_Object($message->getMessageParameters());
if ($parameters->getReturnPathEmail() !== null) {
$mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $parameters->getReturnPathEmail());
Zend_Mail::setDefaultTransport($mailTransport);
}
$mailer = new Zend_Mail('utf-8');
foreach ($message->getRecipients() as $recipient) {
list($email, $name, $type) = $recipient;
switch ($type) {
case self::EMAIL_TYPE_BCC:
$mailer->addBcc($email, '=?utf-8?B?' . base64_encode($name) . '?=');
break;
case self::EMAIL_TYPE_TO:
case self::EMAIL_TYPE_CC:
default:
$mailer->addTo($email, '=?utf-8?B?' . base64_encode($name) . '?=');
break;
}
}
if ($parameters->getIsPlain()) {
$mailer->setBodyText($message->getMessageBody());
} else {
$mailer->setBodyHTML($message->getMessageBody());
}
$mailer->setSubject('=?utf-8?B?' . base64_encode($parameters->getSubject()) . '?=');
$mailer->setFrom($parameters->getFromEmail(), $parameters->getFromName());
if ($parameters->getReplyTo() !== null) {
$mailer->setReplyTo($parameters->getReplyTo());
}
if ($parameters->getReturnTo() !== null) {
$mailer->setReturnPath($parameters->getReturnTo());
}
foreach (Mage::app()->getStores() as $store) {
if ($parameters->getFromEmail() == Mage::getStoreConfig('trans_email/ident_sales/email', $store->getStoreId())) {
$storeid = $store->getStoreId();
}
}
try {
$transport = new Varien_Object();
Mage::dispatchEvent('aschroder_smtppro_queue_before_send', array('mail' => $mailer, 'transport' => $transport, 'message' => $message, 'store_id' => isset($storeid) ? $storeid : null));
if ($transport->getTransport()) {
// if set by an observer, use it
$mailer->send($transport->getTransport());
} else {
$mailer->send();
}
unset($mailer);
$message->setProcessedAt(Varien_Date::formatDate(true));
$message->save();
// loop each email to fire an after send event
foreach ($message->getRecipients() as $recipient) {
list($email, $name, $type) = $recipient;
Mage::dispatchEvent('aschroder_smtppro_after_send', array('to' => $email, 'template' => "queued email", 'subject' => $parameters->getSubject(), 'html' => !$parameters->getIsPlain(), 'email_body' => $message->getMessageBody()));
}
} catch (Exception $e) {
unset($mailer);
$oldDevMode = Mage::getIsDeveloperMode();
Mage::setIsDeveloperMode(true);
Mage::logException($e);
Mage::setIsDeveloperMode($oldDevMode);
return false;
}
// after each valid message has been sent - pause if required
if ($pauseMicros > 0) {
$_helper->log('SMTP Pro pausing.');
usleep($pauseMicros);
}
}
}
return $this;
}