/** * Tests removal of duplicate recipients and reply-tos. */ public function testDuplicateIDNRemoved() { if (!$this->Mail->idnSupported()) { $this->markTestSkipped('intl and/or mbstring extensions are not available'); } $this->Mail->clearAllRecipients(); $this->Mail->clearReplyTos(); $this->Mail->CharSet = 'utf-8'; $this->assertTrue($this->Mail->addAddress('test@françois.ch')); $this->assertFalse($this->Mail->addAddress('test@françois.ch')); $this->assertTrue($this->Mail->addAddress('test@FRANÇOIS.CH')); $this->assertFalse($this->Mail->addAddress('test@FRANÇOIS.CH')); $this->assertTrue($this->Mail->addAddress('*****@*****.**')); $this->assertFalse($this->Mail->addAddress('*****@*****.**')); $this->assertFalse($this->Mail->addAddress('*****@*****.**')); $this->assertTrue($this->Mail->addReplyTo('test+replyto@françois.ch')); $this->assertFalse($this->Mail->addReplyTo('test+replyto@françois.ch')); $this->assertTrue($this->Mail->addReplyTo('test+replyto@FRANÇOIS.CH')); $this->assertFalse($this->Mail->addReplyTo('test+replyto@FRANÇOIS.CH')); $this->assertTrue($this->Mail->addReplyTo('*****@*****.**')); $this->assertFalse($this->Mail->addReplyTo('*****@*****.**')); $this->assertFalse($this->Mail->addReplyTo('*****@*****.**')); $this->buildBody(); $this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo); // There should be only one "To" address and one "Reply-To" address. $this->assertEquals(1, count($this->Mail->getToAddresses()), 'Bad count of "to" recipients'); $this->assertEquals(1, count($this->Mail->getReplyToAddresses()), 'Bad count of "reply-to" addresses'); }
/** * Inner mailer initialization from set variables * * @return void */ protected function initMailFromSet() { $this->mail->setLanguage($this->get('langLocale'), $this->get('langPath')); $this->mail->CharSet = $this->get('charset'); $this->mail->From = $this->get('from'); $this->mail->FromName = $this->get('fromName') ?: $this->get('from'); $this->mail->Sender = $this->get('from'); $this->mail->clearAllRecipients(); $this->mail->clearAttachments(); $this->mail->clearCustomHeaders(); $emails = explode(static::MAIL_SEPARATOR, $this->get('to')); foreach ($emails as $email) { $this->mail->addAddress($email); } $this->mail->Subject = $this->get('subject'); $this->mail->AltBody = $this->createAltBody($this->get('body')); $this->mail->Body = $this->get('body'); // add custom headers foreach ($this->get('customHeaders') as $header) { $this->mail->addCustomHeader($header); } if (is_array($this->get('images'))) { foreach ($this->get('images') as $image) { // Append to $attachment array $this->mail->addEmbeddedImage($image['path'], $image['name'] . '@mail.lc', $image['name'], 'base64', $image['mime']); } } }
/** * Функция отправки сообщения: * * @param string $from - адрес отправителя * @param string $from_name - имя отправителя * @param string|array $to - адрес(-а) получателя * @param string $theme - тема письма * @param string $body - тело письма * @param bool $isText - является ли тело письма текстом * * @return bool отправилось ли письмо **/ public function send($from, $from_name, $to, $theme, $body, $isText = false) { $this->_mailer->clearAllRecipients(); $this->setFrom($from, $from_name); if (is_array($to)) { foreach ($to as $email) { $this->addAddress($email); } } else { $this->addAddress($to); } $this->setSubject($theme); if ($isText) { $this->_mailer->Body = $body; $this->_mailer->isHTML(false); } else { $this->_mailer->msgHTML($body, \Yii::app()->basePath); } try { return $this->_mailer->send(); } catch (\Exception $e) { \Yii::log($e->__toString(), \CLogger::LEVEL_ERROR, 'mail'); return false; } }
/** * Test BCC-only addressing. */ public function testBCCAddressing() { $this->Mail->Subject .= ': BCC-only addressing'; $this->buildBody(); $this->Mail->clearAllRecipients(); $this->assertTrue($this->Mail->addBCC('*****@*****.**'), 'BCC addressing failed'); $this->assertTrue($this->Mail->send(), 'send failed'); }
/** * Clears out all previously specified values for this object and restores * it to the state it was in when it was instantiated. * * @return Email */ public function clear() { $this->PhpMailer->clearAllRecipients(); $this->PhpMailer->Body = ''; $this->PhpMailer->AltBody = ''; $this->from(); $this->_IsToSet = false; $this->mimeType(c('Garden.Email.MimeType', 'text/plain')); $this->_MasterView = 'email.master'; $this->Skipped = array(); return $this; }
/** * 发送邮件 * * @access public * @param string $address 邮件地址 * @param string $subject 邮件标题 * @param string $content 邮件内容 * @return array */ public function send($address, $subject, $content) { $this->phpMailer->MsgHTML(eregi_replace("[\\]", '', $content)); $this->phpMailer->AddAddress($address, ''); if (!$this->phpMailer->Send()) { #重置所有地址 $this->phpMailer->clearAllRecipients(); return array('isSuccess' => false, 'error' => $this->phpMailer->ErrorInfo); } else { #重置所有地址 $this->phpMailer->clearAllRecipients(); return array('isSuccess' => true); } }
/** * $emailConfig['smtp'] = array( * 'stmp_host' => '', * 'user' => '', * 'pwd' => '', * 'port' => '', * 'address' => '', * ); */ public function __construct() { $config = Config::Get('email', 'smtp'); $mailer = new PHPMailer(); $mailer->isSMTP(); $mailer->Host = $config['stmp_host']; $mailer->Username = $config['user']; $mailer->Password = $config['pwd']; $mailer->SMTPAuth = true; $mailer->Port = $config['port']; $mailer->CharSet = "utf-8"; $mailer->setFrom($config['address']); $mailer->isHTML(); $mailer->clearAllRecipients(); $this->phpMailer = $mailer; }
/** * Resets the currently set mailer values back to there default values * * @return $this */ public function reset() { $this->subject = ''; $this->body = ''; $this->htmlBody = ''; $this->urlWeb = ''; $this->mailSignature = ''; $this->from = ''; $this->recipients = null; $this->bcc = false; $this->attachments = []; $this->template = ''; if ($this->phpMailer) { $this->phpMailer->clearAllRecipients(); $this->phpMailer->clearAttachments(); } return $this; }
/** * Clears all recipients assigned in the TO, CC and BCC * array. Returns void. * * @return void */ public function clearAllRecipients() { $this->_aRecipients = array(); parent::clearAllRecipients(); }
/** * Send the notification. * * This method sends the notification to all recipients, rendering the template with the corresponding parameters for each recipient. * @throws phpmailerException The message could not be sent. */ public function send() { $mail = new \PHPMailer(true); $mail->From = $this->from_email; $mail->FromName = $this->from_name; $mail->addReplyTo($this->reply_to_email, $this->reply_to_name); $twig = static::$app->view()->getEnvironment(); // Loop through email recipients, sending customized content to each one foreach ($this->email_recipients as $recipient) { $mail->addAddress($recipient->getEmail(), $recipient->getName()); // Add any CCs and BCCs if ($recipient->getCCs()) { foreach ($recipient->getCCs() as $cc) { $mail->addCC($cc['email'], $cc['name']); } } if ($recipient->getBCCs()) { foreach ($recipient->getBCCs() as $bcc) { $mail->addBCC($bcc['email'], $bcc['name']); } } $params = $recipient->getParams(); // Must manually merge in global variables for block rendering $params = array_merge($twig->getGlobals(), $params); $mail->Subject = $this->template->renderBlock('subject', $params); $mail->Body = $this->template->renderBlock('body', $params); $mail->isHTML(true); // Set email format to HTML // Send mail as SMTP, if desired if (static::$app->config('mail') == 'smtp') { $config = static::$app->config('smtp'); $mail->isSMTP(true); $mail->Host = $config['host']; $mail->Port = $config['port']; $mail->SMTPAuth = $config['auth']; $mail->SMTPSecure = $config['secure']; $mail->Username = $config['user']; $mail->Password = $config['pass']; } // Send mail as sendmail, if desired if (static::$app->config('mail') == 'sendmail') { $config = static::$app->config('sendmail'); $mail->isSendmail(true); } // Try to send the mail. Will throw an exception on failure. $mail->send(); // Clear all PHPMailer recipients (from the message for this iteration) $mail->clearAllRecipients(); } }
/** * Send email. * * @since 1.0 * @access public * @param $type string * @param $init array */ public function mailer($type = 'mail', $init = array()) { global $wpdb, $guiform; $subject = ""; $MsgHTML = ""; $sendTo = array_map('trim', explode(',', $init['to'])); $sendCc = array_map('trim', explode(',', $init['cc'])); $sendBcc = array_map('trim', explode(',', $init['bcc'])); $sendReplyTo = array_map('trim', explode(',', $init['reply-to'])); // Make sure the PHPMailer class has been instantiated // (Re)create it, if it's gone missing if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; $phpmailer = new PHPMailer(true); $phpmailer->clearAllRecipients(); $phpmailer->SMTPAuth = true; } if ($type == 'test-mail') { $data = $wpdb->get_row($wpdb->prepare("SELECT name, value FROM {$wpdb->guiform_options} WHERE id = %d", $this->_id)); $sendTo = array($data->name); $row = unserialize($data->value); $row = array_map('trim', $row); $html = "<strong>" . __('Greetings!', GuiForm_Plugin::NAME) . "</strong><br /><br />"; $html .= __("This is a test message.", GuiForm_Plugin::NAME) . "<br /><br />"; $MsgHTML = self::emailTpl($html); $phpmailer->SetFrom("*****@*****.**", GuiForm_Plugin::PACKAGE); $phpmailer->Subject = __('Test Message', GuiForm_Plugin::NAME); } else { if ($type == 'activation-mail') { $data = $wpdb->get_row($wpdb->prepare("SELECT name, value FROM {$wpdb->guiform_options} WHERE id = %d", $this->_id)); $row = unserialize($data->value); $row = array_map('trim', $row); $mv_code = md5(time()); $row['key'] = $mv_code; $guiform->updateOption($data->name, $row, 'mail', $this->_id); $phpmailer->Subject = __("Email Verification", GuiForm_Plugin::NAME); $sendTo = array($data->name); $vlink = get_site_url() . "/?" . $guiform->getOption('permalink')->value['value'] . '=' . $this->_id . "&mv-code={$mv_code}"; $html = "Hello " . $row['name'] . ",<br /><br />"; $html .= __("To enable this email address from sending emails with your forms we must first verify by clicking the link below:", GuiForm_Plugin::NAME) . "<br /><br />"; $html .= __("Verification Link: ", GuiForm_Plugin::NAME) . "<a target=\"_blank\" href=\"{$vlink}\">" . __("click here!", GuiForm_Plugin::NAME) . "</a><br /><br />"; $MsgHTML = self::emailTpl($html); $phpmailer->SetFrom("*****@*****.**", "GuiForm"); } else { if ($type == 'mail') { $init['message'] = str_replace("\\r\\n", "<br />", $init['message']); $init['message'] = stripcslashes($init['message']); //Do not remove   and <br />. $MsgHTML = $init['message'] . " <br />"; $phpmailer->SetFrom($init['from'], ""); $phpmailer->Subject = $init['subject']; if (sizeof($init['attachment'])) { foreach ($init['attachment'] as $file) { $phpmailer->AddAttachment(self::getAttachmentPath($file['url']), $file['name']); } } if (sizeof($sendReplyTo)) { foreach ($sendReplyTo as $replyTo) { if (is_email($replyTo)) { $phpmailer->AddReplyTo($replyTo); } } } if (sizeof($sendCc)) { foreach ($sendCc as $mailCc) { if (is_email($mailCc)) { $phpmailer->AddCC($mailCc); } } } if (sizeof($sendBcc)) { foreach ($sendBcc as $mailBcc) { if (is_email($mailBcc)) { $phpmailer->AddCC($mailBcc); } } } } } } $phpmailer->Body = html_entity_decode($MsgHTML); $phpmailer->AltBody = strip_tags($MsgHTML); $phpmailer->IsHTML(true); $phpmailer->CharSet = "UTF-8"; foreach ($sendTo as $mailTo) { if ($phpmailer->validateAddress($mailTo)) { $phpmailer->AddAddress($mailTo); } } $smtpSettings = $guiform->getOption($this->form, false, 'smtp')->value; if ($smtpSettings->smtp_enable) { $row['protocol'] = 'smtp'; $row['smtp_host'] = $smtpSettings->smtp_host; $row['smtp_port'] = $smtpSettings->smtp_port; } $phpmailer->Mailer = $row['protocol']; if ($row['protocol'] == 'smtp') { $phpmailer->IsSMTP(); $phpmailer->SMTPSecure = $row['smtp_encryption']; $phpmailer->Host = $row['smtp_host']; $phpmailer->Port = $row['smtp_port']; } if (filter_var($row['smtp_auth'], FILTER_VALIDATE_BOOLEAN)) { $phpmailer->SMTPAuth = true; $phpmailer->Username = trim($row['smtp_username']); $phpmailer->Password = trim($row['smtp_password']); } if (!$phpmailer->send()) { die(__("Mailer Error: ", GuiForm_Plugin::NAME) . $phpmailer->ErrorInfo); } else { $phpmailer->clearAllRecipients(); $phpmailer->clearAttachments(); if ($type !== 'mail') { die(__("Message sent! Please check your email for message.", GuiForm_Plugin::NAME)); } } }
public function sendEmail() { try { $time = Manager::getSysTime(); $ipaddress = $_SERVER['REMOTE_ADDR']; $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = Manager::getConf('mailer.smtpServer'); // SMTP server $mail->From = Manager::getConf('mailer.smtpFrom'); $mail->FromName = Manager::getConf('mailer.smtpFromName'); $mail->Subject = $this->data->assunto; $mail->isHTML(false); $mail->CharSet = 'utf-8'; $body = 'Enviada de: ' . $ipaddress . ' em ' . $time; $mail->Body = $body . "\n" . $this->data->mensagem; $mail->WordWrap = 100; $mail->addAddress($this->data->email); $ok = $mail->send(); $mail->clearAllRecipients(); $this->renderPrompt('information', 'Mensagem enviada com sucesso!'); } catch (Exception $e) { $this->renderPrompt('error', $e->getMessage()); } }
public static function sendGmail($username, $pass, array $email, $charset = 'UTF-8') { $mail = new PHPMailer(); $mail->isSMTP(); $mail->CharSet = $charset; $mail->SMTPDebug = 0; $mail->Host = GMAIL_HOST; $mail->Port = GMAIL_PORT; $mail->SMTPAuth = GMAIL_SMTP_AUTH; $mail->SMTPSecure = GMAIL_SMTP_SECURE; $mail->Username = $username; $mail->Password = $pass; foreach ($email as $to => $email_data) { $mail->clearAllRecipients(); $mail->setFrom($username); $mail->addAddress($to); if (isset($email_data['cc'])) { $mail->clearCCs(); foreach (is_array($email_data['cc']) ? $email_data['cc'] : [$email_data['cc']] as $cc) { $mail->addCC($cc); } } if (isset($email_data['bcc'])) { $mail->clearBCCs(); foreach (is_array($email_data['bcc']) ? $email_data['bcc'] : [$email_data['bcc']] as $bcc) { $mail->addBCC($bcc); } } $mail->Subject = $email_data['subject']; $mail->Body = $email_data['body']; if (!$mail->send()) { throw new Exception(__METHOD__ . $mail->ErrorInfo); } } }
/** * @param string $mailAddress */ public function setMailAddress($mailAddress) { $this->mailer->clearAllRecipients(); self::checkMailValidity($mailAddress); $this->mailer->addAddress($mailAddress); }
function send_mail($path, $mail_lock, $subject, $to = array()) { if (!file_exists($mail_lock)) { //从getwiki.php中得到的更新标志 $tmp_file = './update_' . time() . '.txt'; $ret_text = get_lastlog($path, 1); //########################################## $smtpserver = isset($_ENV["SMTP_SERVER"]) ? $_ENV["SMTP_SERVER"] : "smtp.163.com"; //SMTP服务器 $smtpserverport = isset($_ENV["SMTP_SERVER_PORT"]) ? $_ENV["SMTP_SERVER_PORT"] : "465"; //SMTP服务器端口 $smtpusermail = isset($_ENV["SMTP_USER_MAIL"]) ? $_ENV["SMTP_USER_MAIL"] : ""; //SMTP服务器的用户邮箱 $smtpemailto = isset($_ENV["SMTP_MAIL_TO"]) ? $_ENV["SMTP_MAIL_TO"] : ""; //收件人 $smtpuser = isset($_ENV["SMTP_USER"]) ? $_ENV["SMTP_USER"] : ""; //SMTP服务器的用户帐号 $smtppass = isset($_ENV["SMTP_PASS"]) ? $_ENV["SMTP_PASS"] : ""; //SMTP服务器的用户密码 $mailtype = "HTML"; //邮件格式(HTML/TXT),TXT为文本邮件 $mailsubject = "监测通知:微信公众平台WIKI更新"; //邮件主题 $mailbody = "<h1> 更新内容为: </h1>" . "git日志内容如下:<br><hr>" . nl2br(htmlspecialchars(substr($ret_text, 0, stripos($ret_text, "\ndiff --git")))) . "<br><hr>更多内容,请参看附件" . $tmp_file; //邮件内容 ########################################## if (!$smtpuser) { echo "由于邮箱SMTP账号信息等未配置,邮件未能发送<br />"; return false; //未设置参数则返回 } if (REMOTE_URL !== '') { $mailbody .= "<br>或者点击查看远程仓库页面:<a href=\"" . REMOTE_URL . "\">" . REMOTE_URL . "</a>"; } $mailbody .= '<hr>收到此邮件说明曾经订阅此通知,如不是您本人操作或不想再接收到此通知请单独向我发邮件说明或阅读 <a href="http://help.mail.163.com/faqDetail.do?code=d7a5dc8471cd0c0e8b4b8f4f8e49998b374173cfe9171305fa1ce630d7f67ac28425c7e6c5a286cc.">自助退订方法</a>'; if (empty($to)) { $to = isset($_ENV["SMTP_MAIL_TO2"]) ? $_ENV["SMTP_MAIL_TO2"] : ""; //附加收件人 } $to_arr = preg_split('/[,;\\/\\\\|]/', $smtpemailto); if (is_string($to)) { $to = preg_split('/[,;\\/\\\\|]/', $to); } $to_arr = array_merge($to_arr, $to); $to_count = count($to_arr); $to_arr = array_chunk($to_arr, 20); write($tmp_file, $ret_text); $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP //$mail->SMTPDebug = 1; $mail->SMTPAuth = true; // turn on SMTP authentication $mail->SMTPSecure = "ssl"; $mail->CharSet = "utf-8"; // 这里指定字符集! $mail->Encoding = "base64"; $mail->Host = $smtpserver; // SMTP servers $mail->Port = $smtpserverport; $mail->Username = $smtpuser; // SMTP username 注意:普通邮件认证不需要加 @域名 $mail->Password = $smtppass; // SMTP password $mail->setFrom($smtpusermail, "Auto Robot"); //设置发件人信息 $mail->AddReplyTo($smtpusermail); //回复地址和姓名 $mail->WordWrap = 50; // set word wrap $mail->IsHTML(true); // send as HTML $mail->Subject = $subject ? $subject : $mailsubject; // 邮件主题 $mail->Body = $mailbody; $mail->AltBody = "text/html"; $mail->addAttachment($tmp_file); $sendRet = true; foreach ($to_arr as $to_arr_lite) { foreach ($to_arr_lite as $to_str) { $mail->AddAddress($to_str); // 收件人邮箱和姓名 } $sendRet = $mail->Send() & $sendRet; $mail->clearAllRecipients(); } if ($sendRet) { unlink($tmp_file); echo "邮件发送失败,"; echo "邮件错误信息: " . $mail->ErrorInfo . "<br />"; } else { unlink($tmp_file); echo "邮件已发送到邮箱 <br />"; file_put_contents($mail_lock, 'ok'); } } else { echo "未更新,不发送通知邮件。"; } }
$mail->isMail(); $mail->CharSet = Mailconfig::$charset; $mail->From = Mailconfig::$from; $mail->FromName = Mailconfig::$fromname; // to user $mail->addAddress(Arr::get($posted, 'mail'), Arr::get($posted, 'mail')); $mail->Subject = '【RECRU】事前登録が完了しました'; $mail->Body = "\nRECRU(リクルー)の事前登録を受け付けました。\n" . "\nこの度は就活生同士のクローズドSNS「RECRU(リクルー)」への事前登録\n" . "誠にありがとうございます。\n" . "今後、本サービスの開始まで\n" . "お得な就活情報やサービスリリースに関する情報をお知らせいたしますので、\n" . "ぜひご活用ください!!\n" . "\n※このメールはサービスの事前登録受付後、自動送信されております.\n" . "返信には対応しておりませんので、ご注意くださいませ。\n" . "\n============================================================\n" . "RECRU(リクルー)\n" . "運営事務局\n" . "http://recru.asia" . ""; $mailfailed = ""; if (!$mail->send()) { $mailfailed = "\n事前登録のメールの送信に失敗しました。\n" . "手動での送信が必要になります\n" . "以下登録者への完了メール===================\n\n" . "件名: " . $mail->Subject . "\n" . "本文:\n" . $mail->Body . "\n" . "\n===============登録者への完了メール内容ここまで\n" . ""; $logger->error("ユーザーへのメール送信に失敗しました。"); $logger->error($mail->ErrorInfo); } // to bellpark $mail->clearAllRecipients(); foreach (Mailconfig::$to as $address => $name) { $mail->addAddress($address, $name); } foreach (Mailconfig::$cc as $address => $name) { $mail->addCC($address, $name); } foreach (Mailconfig::$bcc as $address => $name) { $mail->addBCC($address, $name); } $mail->Subject = '【RECRU】事前登録の受付'; $mail->Body = "\nサービスの事前登録を受け付けました。\n\n" . $mailfailed . "メールアドレス:{$posted['mail']}\n" . "\n※このメールはサービスの事前登録受付後、自動送信されております.\n" . "返信には対応しておりませんので、ご注意くださいませ。\n" . "\n============================================================\n" . "RECRU(リクルー)\n" . "運営事務局\n" . "http://recru.asia" . ""; if (!$mail->send()) { $logger->fatal("管理者へのメール送信に失敗しました。"); $logger->fatal($mail->ErrorInfo); $logger->fatal($mail->Body);
/** * Send an email using phpmailer * * @param string $from From address * @param string $from_name From name * @param string $to To address * @param string $to_name To name * @param string $subject The subject of the message. * @param string $body The message body * @param array $bcc Array of address strings * @param bool $html Set true for html email, also consider setting * altbody in $params array * @param array $files Array of file descriptor arrays, each file array * consists of full path and name * @param array $params Additional parameters * @return bool */ function phpmailer_gmail_send($from, $from_name, $to, $to_name, $subject, $body, array $bcc = NULL, $html = false, array $files = NULL, array $params = NULL) { static $phpmailer; // Ensure phpmailer object exists if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) { require_once elgg_get_plugins_path() . '/phpmailer_gmail/vendors/phpmailer/PHPMailerAutoload.php'; $phpmailer = new PHPMailer(); } if (!$from) { throw new NotificationException(sprintf(elgg_echo('NotificationException:MissingParameter'), 'from')); } if (!$to && !$bcc) { throw new NotificationException(sprintf(elgg_echo('NotificationException:MissingParameter'), 'to')); } if (!$subject) { throw new NotificationException(sprintf(elgg_echo('NotificationException:MissingParameter'), 'subject')); } // set line ending if admin selected \n (if admin did not change setting, null is returned) if (elgg_get_plugin_setting('nonstd_mta', 'phpmailer')) { $phpmailer->LE = "\n"; } else { $phpmailer->LE = "\r\n"; } //////////////////////////////////// // Format message $phpmailer->clearAllRecipients(); $phpmailer->clearAttachments(); // Set the from name and email //$phpmailer->From = $from; //$phpmailer->FromName = $from_name; //Set who the message is to be sent from $phpmailer->setFrom($from, $from_name); //Set an alternative reply-to address $phpmailer->addReplyTo($from, $from_name); // Set destination address if (isset($to)) { $phpmailer->addAddress($to, $to_name); } // set bccs if exists if ($bcc && is_array($bcc)) { foreach ($bcc as $address) { $phpmailer->addBCC($address, $address); } } $phpmailer->Subject = $subject; if (!$html) { $phpmailer->CharSet = 'utf-8'; $phpmailer->isHTML(false); if ($params && array_key_exists('altbody', $params)) { $phpmailer->AltBody = $params['altbody']; } $trans_tbl = get_html_translation_table(HTML_ENTITIES); $trans_tbl[chr(146)] = '’'; foreach ($trans_tbl as $k => $v) { $ttr[$v] = utf8_encode($k); } $source = strtr($body, $ttr); $body = strip_tags($source); } else { $phpmailer->isHTML(true); } $phpmailer->Body = $body; if ($files && is_array($files)) { foreach ($files as $file) { if (isset($file['path'])) { $phpmailer->addAttachment($file['path'], $file['name']); } } } $is_smtp = elgg_get_plugin_setting('phpmailer_gmail_smtp', 'phpmailer_gmail'); $smtp_host = elgg_get_plugin_setting('phpmailer_gmail_host', 'phpmailer_gmail'); $smtp_auth = elgg_get_plugin_setting('phpmailer_gmail_smtp_auth', 'phpmailer_gmail'); $is_tls = elgg_get_plugin_setting('ep_phpmailer_gmail_tls', 'phpmailer_gmail'); $tls_port = elgg_get_plugin_setting('ep_phpmailer_gmail_port', 'phpmailer_gmail'); if ($is_smtp && isset($smtp_host)) { //Enable SMTP debugging // 0 = off (for production use) // 1 = client messages // 2 = client and server messages $phpmailer->SMTPDebug = 0; $phpmailer->IsSMTP(); $phpmailer->Host = $smtp_host; $phpmailer->SMTPAuth = false; if ($smtp_auth) { $phpmailer->SMTPAuth = true; $phpmailer->Username = elgg_get_plugin_setting('phpmailer_username', 'phpmailer'); $phpmailer->Password = elgg_get_plugin_setting('phpmailer_password', 'phpmailer'); if ($is_tls) { $phpmailer->SMTPSecure = "tls"; $phpmailer->Port = $tls_port; } } } else { // use php's mail $phpmailer->isMail(); } $return = $phpmailer->send(); if (!$return) { elgg_log('PHPMailer error: ' . $phpmailer->ErrorInfo, 'WARNING'); } return $return; }
/** * Send email(s). * * @since 2.5.0 * * @param BP_Email $email Email to send. * @return bool|WP_Error Returns true if email send, else a descriptive WP_Error. */ public function bp_email(BP_Email $email) { static $phpmailer = null; if ($phpmailer === null) { if (!class_exists('PHPMailer')) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; } $phpmailer = new PHPMailer(true); } /* * Resets. */ $phpmailer->clearAllRecipients(); $phpmailer->clearAttachments(); $phpmailer->clearCustomHeaders(); $phpmailer->clearReplyTos(); $phpmailer->Sender = ''; /* * Set up. */ $phpmailer->IsMail(); $phpmailer->CharSet = bp_get_option('blog_charset'); $phpmailer->Hostname = self::get_hostname(); /* * Content. */ $phpmailer->Subject = $email->get_subject('replace-tokens'); $content_plaintext = PHPMailer::normalizeBreaks($email->get_content_plaintext('replace-tokens')); if ($email->get('content_type') === 'html') { $phpmailer->msgHTML($email->get_template('add-content'), '', 'wp_strip_all_tags'); $phpmailer->AltBody = $content_plaintext; } else { $phpmailer->IsHTML(false); $phpmailer->Body = $content_plaintext; } $recipient = $email->get_from(); try { $phpmailer->SetFrom($recipient->get_address(), $recipient->get_name(), false); } catch (phpmailerException $e) { } $recipient = $email->get_reply_to(); try { $phpmailer->addReplyTo($recipient->get_address(), $recipient->get_name()); } catch (phpmailerException $e) { } $recipients = $email->get_to(); foreach ($recipients as $recipient) { try { $phpmailer->AddAddress($recipient->get_address(), $recipient->get_name()); } catch (phpmailerException $e) { } } $recipients = $email->get_cc(); foreach ($recipients as $recipient) { try { $phpmailer->AddCc($recipient->get_address(), $recipient->get_name()); } catch (phpmailerException $e) { } } $recipients = $email->get_bcc(); foreach ($recipients as $recipient) { try { $phpmailer->AddBcc($recipient->get_address(), $recipient->get_name()); } catch (phpmailerException $e) { } } $headers = $email->get_headers(); foreach ($headers as $name => $content) { $phpmailer->AddCustomHeader($name, $content); } /** * Fires after PHPMailer is initialised. * * @since 2.5.0 * * @param PHPMailer $phpmailer The PHPMailer instance. */ do_action('bp_phpmailer_init', $phpmailer); /** This filter is documented in wp-includes/pluggable.php */ do_action_ref_array('phpmailer_init', array(&$phpmailer)); try { return $phpmailer->Send(); } catch (phpmailerException $e) { return new WP_Error($e->getCode(), $e->getMessage(), $email); } }
/** * Send a prepared and rendered email locally. * * @param array $email * @return bool */ protected function send_prepared(array $email) { if (!is_email($email['to_address'])) { Prompt_Logging::add_error(Prompt_Enum_Error_Codes::OUTBOUND, __('Attempted to send to an invalid email address.', 'Postmatic'), compact('email')); return false; } $this->local_mailer->clearAllRecipients(); $this->local_mailer->clearCustomHeaders(); $this->local_mailer->clearReplyTos(); $this->local_mailer->From = $email['from_address']; $this->local_mailer->FromName = $email['from_name']; $this->local_mailer->addAddress($email['to_address'], $email['to_name']); if (!empty($email['reply_address'])) { $this->local_mailer->addReplyTo($email['reply_address'], $email['reply_name']); } $unsubscribe_types = array(Prompt_Enum_Message_Types::COMMENT, Prompt_Enum_Message_Types::POST); if (!empty($email['reply_address']) and in_array($email['message_type'], $unsubscribe_types)) { $this->local_mailer->addCustomHeader('List-Unsubscribe', '<mailto:' . $email['reply_address'] . '?body=unsubscribe>'); } $this->local_mailer->Subject = $email['subject']; $this->local_mailer->Body = $email['html_content']; $this->local_mailer->AltBody = $email['text_content']; $this->local_mailer->ContentType = Prompt_Enum_Content_Types::HTML; $this->local_mailer->isMail(); $this->local_mailer->CharSet = 'UTF-8'; try { $this->local_mailer->send(); } catch (phpmailerException $e) { Prompt_Logging::add_error('prompt_wp_mail', __('Failed sending an email locally. Did you know Postmatic can deliver email for you?', 'Prompt_Core'), array('email' => $email, 'error_info' => $this->local_mailer->ErrorInfo)); return false; } return true; }