本文整理汇总了PHP中PHPMailer::IsError方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPMailer::IsError方法的具体用法?PHP PHPMailer::IsError怎么用?PHP PHPMailer::IsError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPMailer
的用法示例。
在下文中一共展示了PHPMailer::IsError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendgmail
function sendgmail($addr, $body)
{
$config = parse_ini_file('../../catchit/email_config.ini');
require_once "phpmailer/class.phpmailer.php";
include "phpmailer/class.smtp.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = $config['address'];
$mail->Password = $config['password'];
$mail->Priority = 3;
$mail->CharSet = 'UTF-8';
$mail->Encoding = '8bit';
$mail->Subject = 'Data from Catchit';
$mail->ContentType = 'text/html; charset=utf-8\\r\\n';
$mail->From = $config['address'];
$mail->FromName = 'Catchit';
$mail->WordWrap = 900;
$mail->AddAddress($addr);
$mail->isHTML(FALSE);
$mail->Body = $body;
$mail->Send();
$mail->SmtpClose();
if ($mail->IsError()) {
return 'failed to send';
} else {
return 'Email has been sent';
}
}
示例2: send
/**
* Short description of method send
*
* @access public
* @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
* @return int
*/
public function send()
{
$returnValue = (int) 0;
foreach ($this->messages as $message) {
if ($message instanceof tao_helpers_transfert_Message) {
$this->mailer->SetFrom($message->getFrom());
$this->mailer->AddReplyTo($message->getFrom());
$this->mailer->Subject = $message->getTitle();
$this->mailer->AltBody = strip_tags(preg_replace("/<br.*>/i", "\n", $message->getBody()));
$this->mailer->MsgHTML($message->getBody());
$this->mailer->AddAddress($message->getTo());
try {
if ($this->mailer->Send()) {
$message->setStatus(tao_helpers_transfert_Message::STATUS_SENT);
$returnValue++;
}
if ($this->mailer->IsError()) {
if (DEBUG_MODE) {
echo $this->mailer->ErrorInfo . "<br>";
}
$message->setStatus(tao_helpers_transfert_Message::STATUS_ERROR);
}
} catch (phpmailerException $pe) {
if (DEBUG_MODE) {
print $pe;
}
}
}
$this->mailer->ClearReplyTos();
$this->mailer->ClearAllRecipients();
}
$this->mailer->SmtpClose();
return (int) $returnValue;
}
示例3:
/**
* Test error handling
*/
function test_Error()
{
$this->Mail->Subject .= ": This should be sent";
$this->BuildBody();
$this->Mail->ClearAllRecipients();
// no addresses should cause an error
$this->assertTrue($this->Mail->IsError() == false, "Error found");
$this->assertTrue($this->Mail->Send() == false, "Send succeeded");
$this->assertTrue($this->Mail->IsError(), "No error found");
$this->assertEquals('You must provide at least one recipient email address.', $this->Mail->ErrorInfo);
$this->Mail->AddAddress($_REQUEST['mail_to']);
$this->assertTrue($this->Mail->Send(), "Send failed");
}
示例4: SendMail
function SendMail($ToEmail, $subject, $MessageHTML)
{
require_once 'class.phpmailer.php';
// Add the path as appropriate
$Mail = new PHPMailer();
$Mail->IsSMTP();
// Use SMTP
$Mail->Host = "smtp.gmail.com";
// Sets SMTP server
$Mail->SMTPDebug = 2;
// 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE;
// enable SMTP authentication
$Mail->SMTPSecure = "tls";
//Secure conection
$Mail->Port = 587;
// set the SMTP port
$Mail->Username = 'jitendra291192@gmail.com';
// SMTP account username
$Mail->Password = '222@jkc999@jkc';
// SMTP account password
$Mail->Priority = 1;
// Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = $subject;
$Mail->ContentType = 'text/html; charset=utf-8\\r\\n';
$Mail->From = 'jitendrachaudhary@iitj.ac.in';
$Mail->FromName = 'Jitendra Chaudhary';
$Mail->WordWrap = 900;
// RFC 2822 Compliant for Max 998 characters per line
$Mail->AddAddress($ToEmail);
// To:
$Mail->isHTML(TRUE);
$Mail->Body = $MessageHTML;
//$Mail->AltBody = $MessageTEXT;
$Mail->Send();
$Mail->SmtpClose();
if ($Mail->IsError()) {
// ADDED - This error checking was missing
return FALSE;
echo "check your email address";
} else {
return TRUE;
}
}
示例5:
/**
* Test error handling
*/
function test_Error()
{
$this->Mail->Subject .= ": This should be sent";
$this->BuildBody();
$this->Mail->ClearAllRecipients(); // no addresses should cause an error
$this->assertTrue($this->Mail->IsError() == false, "Error found");
$this->assertTrue($this->Mail->Send() == false, "Send succeeded");
$this->assertTrue($this->Mail->IsError(), "No error found");
$this->assertEquals('You must provide at least one recipient email address.', $this->Mail->ErrorInfo);
if(!isset($_REQUEST['mail_to'])){
$this->markTestSkipped('Skipping re-send after removing addresses, no address requested.');
return;
}
$this->Mail->AddAddress($_REQUEST['mail_to']);
$this->assertTrue($this->Mail->Send(), "Send failed");
}
示例6: compose
/**
* Composes mail message.
*
* @param string $from The sender email address
* @param string $to The email address to send mail to
* @param string $dir The directiry there mail parts template located
* @param array $customHeaders The headers you want to add/replace to. OPTIONAL
* @param string $interface Interface to use for mail OPTIONAL
* @param string $languageCode Language code OPTIONAL
*
* @return void
*/
public function compose($from, $to, $dir, $customHeaders = array(), $interface = \XLite::CUSTOMER_INTERFACE, $languageCode = '')
{
static::$composeRunned = true;
if ('' == $languageCode && \XLite::ADMIN_INTERFACE == $interface && !\XLite::isAdminZone()) {
$languageCode = \XLite\Core\Config::getInstance()->General->default_admin_language;
}
\XLite\Core\Translation::setTmpMailTranslationCode($languageCode);
// initialize internal properties
$this->set('from', $from);
$this->set('to', $to);
$this->set('customHeaders', $customHeaders);
$this->set('dir', $dir);
$subject = $this->compile($this->get('subjectTemplate'), $interface);
$subject = \XLite\Core\Mailer::getInstance()->populateVariables($subject);
$this->set('subject', $subject);
$this->set('body', $this->compile($this->get('layoutTemplate'), $interface));
$body = $this->get('body');
$body = \XLite\Core\Mailer::getInstance()->populateVariables($body);
// find all images and fetch them; replace with cid:...
$fname = tempnam(LC_DIR_COMPILE, 'mail');
file_put_contents($fname, $body);
$this->imageParser = new \XLite\Model\MailImageParser();
$this->imageParser->webdir = \XLite::getInstance()->getShopURL('', false);
$this->imageParser->parse($fname);
$this->set('body', $this->imageParser->result);
$this->set('images', $this->imageParser->images);
ob_start();
// Initialize PHPMailer from configuration variables (it should be done once in a script execution)
$this->initMailFromConfig();
// Initialize Mail from inner set of variables.
$this->initMailFromSet();
$output = ob_get_contents();
ob_end_clean();
if ('' !== $output) {
\XLite\Logger::getInstance()->log('Mailer echoed: "' . $output . '". Error: ' . $this->mail->ErrorInfo);
}
// Check if there is any error during mail composition. Log it.
if ($this->mail->IsError()) {
\XLite\Logger::getInstance()->log('Compose mail error: ' . $this->mail->ErrorInfo);
}
if (file_exists($fname)) {
unlink($fname);
}
\XLite\Core\Translation::setTmpMailTranslationCode('');
static::$composeRunned = false;
}
示例7: SendMail
function SendMail($ToEmail, $Subject, $MessageHTML, $MessageTEXT)
{
require ROOT . 'resources/phpmailer/PHPMailerAutoload.php';
// Add the path as appropriate
$Mail = new PHPMailer();
$Mail->IsSMTP();
// Use SMTP
$Mail->Host = "smtpauth.bluewin.ch";
// Sets SMTP server
$Mail->SMTPDebug = 2;
// 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE;
// enable SMTP authentication
// $Mail->SMTPSecure = "tls"; // Secure conection
$Mail->Port = 587;
// set the SMTP port
$Mail->Username = 'xampp@bluewin.ch';
// SMTP account username
$Mail->Password = 'prophEcy88';
// SMTP account password
$Mail->Priority = 1;
// Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = $Subject;
$Mail->ContentType = 'text/html; charset=utf-8\\r\\n';
$Mail->From = 'xampp@bluewin.ch';
$Mail->FromName = 'The Breakfast Company - XAMPP';
$Mail->WordWrap = 900;
// RFC 2822 Compliant for Max 998 characters per line
$Mail->AddAddress($ToEmail);
// To:
$Mail->addCC("webp@nellen.it");
$Mail->isHTML(TRUE);
$Mail->Body = $MessageHTML;
$Mail->AltBody = $MessageTEXT;
$Mail->Send();
$Mail->SmtpClose();
if ($Mail->IsError()) {
// ADDED - This error checking was missing
return FALSE;
} else {
return TRUE;
}
}
示例8: send_mail
function send_mail($from, $to, $subject, $message)
{
require_once "class.phpmailer.php";
$mail = new PHPMailer();
//建立邮件发送类
$mail->IsSMTP();
// 使用SMTP方式发送
$mail->Host = MAIL_SMTP_HOST;
// 您的企业邮局域名
$mail->SMTPAuth = true;
// 启用SMTP验证功能
$mail->Username = MAIL_SMTP_USER;
// 邮局用户名(请填写完整的email地址)
$mail->Password = MAIL_SMTP_PASS;
// 邮局密码
$mail->From = MAIL_FROM;
//邮件发送者email地址
$mail->FromName = MAIL_FROM_NAME;
$mail->AddAddress("{$to}", MAIL_TO_NAME);
//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")
//$mail->AddReplyTo("", "");
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件
//Add Attachment
if (count($_FILES) > 0) {
foreach ($_FILES as $f) {
$mail->AddAttachment($f['tmp_name'], $f['name']);
}
}
$mail->IsHTML(true);
// set email format to HTML //是否使用HTML格式
$mail->Subject = $subject;
//邮件标题
$mail->Body = $message;
//邮件内容
//$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息,可以省略
$mail->Send();
if ($mail->IsError()) {
die($mail->ErrorInfo);
}
}
示例9: compose
/**
* Composes mail message.
*
* @param string $from The sender email address
* @param string $to The email address to send mail to
* @param string $dir The directiry there mail parts template located
* @param array $customHeaders The headers you want to add/replace to. OPTIONAL
* @param string $interface Interface to use for mail OPTIONAL
*
* @return void
*/
public function compose($from, $to, $dir, $customHeaders = array(), $interface = \XLite::CUSTOMER_INTERFACE)
{
static::$composeRunned = true;
// initialize internal properties
$this->set('from', $from);
$this->set('to', $to);
$this->set('customHeaders', $customHeaders);
$dir .= '/';
$this->set('subject', $this->compile($dir . $this->get('subjectTemplate'), $interface));
$this->set('signature', $this->compile($this->get('signatureTemplate'), $interface));
$this->set('body', $this->compile($dir . $this->get('bodyTemplate'), $interface));
// find all images and fetch them; replace with cid:...
$fname = tempnam(LC_DIR_COMPILE, 'mail');
file_put_contents($fname, $this->get('body'));
$this->imageParser = new \XLite\Model\MailImageParser();
$this->imageParser->webdir = \XLite::getInstance()->getShopURL();
$this->imageParser->parse($fname);
$this->set('body', $this->imageParser->result);
$this->set('images', $this->imageParser->images);
ob_start();
// Initialize PHPMailer from configuration variables (it should be done once in a script execution)
$this->initMailFromConfig();
// Initialize Mail from inner set of variables.
$this->initMailFromSet();
$output = ob_get_contents();
ob_end_clean();
if ('' !== $output) {
\XLite\Logger::getInstance()->log('Mailer echoed: "' . $output . '". Error: ' . $this->mail->ErrorInfo);
}
// Check if there is any error during mail composition. Log it.
if ($this->mail->IsError()) {
\XLite\Logger::getInstance()->log('Compose mail error: ' . $this->mail->ErrorInfo);
}
if (file_exists($fname)) {
unlink($fname);
}
static::$composeRunned = false;
}
示例10: email
function email($fromName, $to, $subject, $body)
{
require_once 'class.phpmailer.php';
$Mail = new PHPMailer();
$Mail->IsSMTP();
$Mail->Host = "hostname.com";
//SMTP server
$Mail->SMTPDebug = 0;
$Mail->SMTPAuth = TRUE;
$Mail->SMTPSecure = "tls";
$Mail->Port = 587;
//SMTP port
$Mail->Username = 'username';
//SMTP account username
$Mail->Password = 'password';
//SMTP account password
$Mail->Priority = 1;
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = $subject;
$Mail->ContentType = 'text/html; charset=utf-8\\r\\n';
$Mail->From = 'email@domain.com';
$Mail->FromName = $fromName;
$Mail->WordWrap = 900;
$Mail->AddAddress($to);
$Mail->isHTML(TRUE);
$Mail->Body = $body;
$Mail->AltBody = $body;
$Mail->Send();
$Mail->SmtpClose();
if ($Mail->IsError()) {
return 'emailNotSent';
} else {
return 'emailSent';
}
}
示例11: SendEmail
function SendEmail($sSubject, $sMessage, $attachName, $hasAttach, $sRecipient)
{
global $sSendType;
global $sFromEmailAddress;
global $sFromName;
global $sLangCode;
global $sLanguagePath;
global $sSMTPAuth;
global $sSMTPUser;
global $sSMTPPass;
global $sSMTPHost;
global $sSERVERNAME;
global $sUSER;
global $sPASSWORD;
global $sDATABASE;
global $sSQL_ERP;
global $sSQL_EMP;
$iUserID = $_SESSION['iUserID'];
// Retrieve UserID for faster access
// Store these queries in variables. (called on every loop iteration)
$sSQLGetEmail = 'SELECT * FROM email_recipient_pending_erp ' . "WHERE erp_usr_id='{$iUserID}' " . 'ORDER BY erp_num_attempt, erp_id LIMIT 1';
// Just run this one ahead of time to get the message subject and body
$sSQL = 'SELECT * FROM email_message_pending_emp';
extract(mysql_fetch_array(RunQuery($sSQL)));
// Keep track of how long this script has been running. To avoid server
// and browser timeouts break out of loop every $sLoopTimeout seconds and
// redirect back to EmailSend.php with meta refresh until finished.
$tStartTime = time();
$mail = new PHPMailer();
// Set the language for PHPMailer
$mail->SetLanguage($sLangCode, $sLanguagePath);
if ($mail->IsError()) {
echo 'PHPMailer Error with SetLanguage(). Other errors (if any) may not report.<br>';
}
$mail->CharSet = 'utf-8';
$mail->From = $sFromEmailAddress;
// From email address (User Settings)
$mail->FromName = $sFromName;
// From name (User Settings)
if ($hasAttach) {
$mail->AddAttachment("tmp_attach/" . $attachName);
}
if (strtolower($sSendType) == 'smtp') {
$mail->IsSMTP();
// tell the class to use SMTP
$mail->SMTPKeepAlive = true;
// keep connection open until last email sent
$mail->SMTPAuth = $sSMTPAuth;
// Server requires authentication
if ($sSMTPAuth) {
$mail->Username = $sSMTPUser;
// SMTP username
$mail->Password = $sSMTPPass;
// SMTP password
}
$delimeter = strpos($sSMTPHost, ':');
if ($delimeter === FALSE) {
$sSMTPPort = 25;
// Default port number
} else {
$sSMTPPort = substr($sSMTPHost, $delimeter + 1);
$sSMTPHost = substr($sSMTPHost, 0, $delimeter);
}
if (is_int($sSMTPPort)) {
$mail->Port = $sSMTPPort;
} else {
$mail->Port = 25;
}
$mail->Host = $sSMTPHost;
// SMTP server name
} else {
$mail->IsSendmail();
// tell the class to use Sendmail
}
$bContinue = TRUE;
$sLoopTimeout = 30;
// Break out of loop if this time is exceeded
$iMaxAttempts = 3;
// Error out if an email address fails 3 times
while ($bContinue) {
// Three ways to get out of this loop
// 1. We're finished sending email
// 2. Time exceeds $sLoopTimeout
// 3. Something strange happens
// (maybe user tries to send from multiple sessions
// causing counts and timestamps to 'misbehave' )
$tTimeStamp = date('Y-m-d H:i:s');
$mail->Subject = $sSubject;
$mail->Body = $sMessage;
if ($sRecipient == 'get_recipients_from_mysql') {
$rsEmailAddress = RunQuery($sSQLGetEmail);
// This query has limit one to pick up one recipient
$aRow = mysql_fetch_array($rsEmailAddress);
extract($aRow);
$mail->AddAddress($erp_email_address);
} else {
$erp_email_address = $sRecipient;
$mail->AddAddress($erp_email_address);
$bContinue = FALSE;
// Just sending one email
//.........这里部分代码省略.........
示例12: mail
function mail($to, $subject, $message, $headers = null)
{
$this->logger->debug('mail> To: ' . $to);
$this->logger->debug('mail> Subject: ' . $subject);
if (empty($subject)) {
$this->logger->debug('mail> Subject empty, skipped');
return true;
}
// Message carrige returns and line feeds clean up
if (!is_array($message)) {
$message = str_replace("\r\n", "\n", $message);
$message = str_replace("\r", "\n", $message);
$message = str_replace("\n", "\r\n", $message);
} else {
if (!empty($message['text'])) {
$message['text'] = str_replace("\r\n", "\n", $message['text']);
$message['text'] = str_replace("\r", "\n", $message['text']);
$message['text'] = str_replace("\n", "\r\n", $message['text']);
}
if (!empty($message['html'])) {
$message['html'] = str_replace("\r\n", "\n", $message['html']);
$message['html'] = str_replace("\r", "\n", $message['html']);
$message['html'] = str_replace("\n", "\r\n", $message['html']);
}
}
if ($this->mail_method != null) {
return call_user_func($this->mail_method, $to, $subject, $message, $headers);
}
if ($this->mailer == null) {
$this->mailer_init();
}
// Simple message is asumed to be html
if (!is_array($message)) {
$this->mailer->IsHTML(true);
$this->mailer->Body = $message;
} else {
// Only html is present?
if (empty($message['text'])) {
$this->mailer->IsHTML(true);
$this->mailer->Body = $message['html'];
} else {
if (empty($message['html'])) {
$this->mailer->IsHTML(false);
$this->mailer->Body = $message['text'];
} else {
$this->mailer->IsHTML(true);
$this->mailer->Body = $message['html'];
$this->mailer->AltBody = $message['text'];
}
}
}
$this->mailer->Subject = $subject;
$this->mailer->ClearCustomHeaders();
if (!empty($headers)) {
foreach ($headers as $key => $value) {
$this->mailer->AddCustomHeader($key . ': ' . $value);
}
}
$this->mailer->ClearAddresses();
$this->mailer->AddAddress($to);
$this->mailer->Send();
if ($this->mailer->IsError()) {
$this->logger->error('mail> ' . $this->mailer->ErrorInfo);
// If the error is due to SMTP connection, the mailer cannot be reused since it does not clean up the connection
// on error.
$this->mailer = null;
return false;
}
return true;
}
示例13: array
$mail->SMTPAutoTLS = false;
if ($controls->data['ssl_insecure'] == 1) {
$mail->SMTPOptions = array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true));
}
if (!empty($controls->data['user'])) {
$mail->SMTPAuth = true;
$mail->Username = $controls->data['user'];
$mail->Password = $controls->data['pass'];
}
$mail->SMTPKeepAlive = true;
$mail->ClearAddresses();
$mail->AddAddress($controls->data['test_email']);
$mail->Send();
$mail->SmtpClose();
$debug = htmlspecialchars(ob_get_clean());
if ($mail->IsError()) {
$controls->errors = '<strong>Connection/email delivery failed.</strong><br>You should contact your provider reporting the SMTP parameter and asking about connection to that SMTP.<br><br>';
$controls->errors = $mail->ErrorInfo;
} else {
$controls->messages = 'Success.';
}
$controls->messages .= '<textarea style="width:100%; height:200px; font-size:12px; font-family: monospace">';
$controls->messages .= $debug;
$controls->messages .= '</textarea>';
}
}
?>
<div class="wrap" id="tnp-wrap">
<?php
示例14: sendmessage
//.........这里部分代码省略.........
$mail->AddAddress($toadd, $toname);
$i++;
}
} else {
// $toaddress is not an array -> old logic
$toname = '';
if (isset($args['toname'])) {
$toname = $args['toname'];
}
// process multiple names entered in a single field separated by commas (#262)
foreach (explode(',', $args['toaddress']) as $toadd) {
$mail->AddAddress($toadd, $toname == '' ? $toadd : $toname);
}
}
// if replytoname and replytoaddress have been provided us them
// otherwise take the fromaddress, fromname we build earlier
if (!isset($args['replytoname']) || empty($args['replytoname'])) {
$args['replytoname'] = $mail->FromName;
}
if (!isset($args['replytoaddress']) || empty($args['replytoaddress'])) {
$args['replytoaddress'] = $mail->From;
}
$mail->AddReplyTo($args['replytoaddress'], $args['replytoname']);
// add any cc addresses
if (isset($args['cc']) && is_array($args['cc'])) {
foreach ($args['cc'] as $email) {
if (isset($email['name'])) {
$mail->AddCC($email['address'], $email['name']);
} else {
$mail->AddCC($email['address']);
}
}
}
// add any bcc addresses
if (isset($args['bcc']) && is_array($args['bcc'])) {
foreach ($args['bcc'] as $email) {
if (isset($email['name'])) {
$mail->AddBCC($email['address'], $email['name']);
} else {
$mail->AddBCC($email['address']);
}
}
}
// add any custom headers
if (isset($args['headers']) && is_string($args['headers'])) {
$args['headers'] = explode("\n", $args['headers']);
}
if (isset($args['headers']) && is_array($args['headers'])) {
foreach ($args['headers'] as $header) {
$mail->AddCustomHeader($header);
}
}
// add message subject and body
$mail->Subject = $args['subject'];
$mail->Body = $args['body'];
if (isset($args['altbody']) && !empty($args['altbody'])) {
$mail->AltBody = $args['altbody'];
}
// add attachments
if (isset($args['attachments']) && !empty($args['attachments'])) {
foreach ($args['attachments'] as $attachment) {
if (is_array($attachment)) {
if (count($attachment) != 4) {
// skip invalid arrays
continue;
}
$mail->AddAttachment($attachment[0], $attachment[1], $attachment[2], $attachment[3]);
} else {
$mail->AddAttachment($attachment);
}
}
}
// add string attachments.
if (isset($args['stringattachments']) && !empty($args['stringattachments'])) {
foreach ($args['stringattachments'] as $attachment) {
if (is_array($attachment) && count($attachment) == 4) {
$mail->AddStringAttachment($attachment[0], $attachment[1], $attachment[2], $attachment[3]);
}
}
}
// add embedded images
if (isset($args['embeddedimages']) && !empty($args['embeddedimages'])) {
foreach ($args['embeddedimages'] as $embeddedimage) {
$ret = $mail->AddEmbeddedImage($embeddedimage['path'], $embeddedimage['cid'], $embeddedimage['name'], $embeddedimage['encoding'], $embeddedimage['type']);
}
}
// send message
if (!$mail->Send()) {
// message not send
$args['errorinfo'] = $mail->IsError() ? $mail->ErrorInfo : __('Error! An unidentified problem occurred while sending the e-mail message.');
LogUtil::log(__f('Error! A problem occurred while sending an e-mail message from \'%1$s\' (%2$s) to (%3$s) (%4$s) with the subject line \'%5$s\': %6$s', $args));
if (SecurityUtil::checkPermission('Mailer::', '::', ACCESS_ADMIN)) {
return LogUtil::registerError($args['errorinfo']);
} else {
return LogUtil::registerError(__('Error! A problem occurred while sending the e-mail message.'));
}
}
return true;
// message sent
}
示例15: mail
function mail($to, $subject, $message, $headers = null)
{
$this->mail_last_error = '';
$this->logger->debug('mail> To: ' . $to);
$this->logger->debug('mail> Subject: ' . $subject);
if (empty($subject)) {
$this->logger->debug('mail> Subject empty, skipped');
return true;
}
// Message carrige returns and line feeds clean up
if (!is_array($message)) {
$message = str_replace("\r\n", "\n", $message);
$message = str_replace("\r", "\n", $message);
$message = str_replace("\n", "\r\n", $message);
} else {
if (!empty($message['text'])) {
$message['text'] = str_replace("\r\n", "\n", $message['text']);
$message['text'] = str_replace("\r", "\n", $message['text']);
$message['text'] = str_replace("\n", "\r\n", $message['text']);
}
if (!empty($message['html'])) {
$message['html'] = str_replace("\r\n", "\n", $message['html']);
$message['html'] = str_replace("\r", "\n", $message['html']);
$message['html'] = str_replace("\n", "\r\n", $message['html']);
}
}
if ($this->mail_method != null) {
return call_user_func($this->mail_method, $to, $subject, $message, $headers);
}
if ($this->mailer == null) {
$this->mailer_init();
}
if ($this->mailer == null) {
// If still null, we need to use wp_mail()...
$headers = array();
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-Type: text/html;charset=UTF-8';
$headers[] = 'From: ' . $this->options['sender_name'] . ' <' . $this->options['sender_email'] . '>';
if (!empty($this->options['return_path'])) {
$headers[] = 'Return-Path: ' . $this->options['return_path'];
}
if (!empty($this->options['reply_to'])) {
$headers[] = 'Reply-To: ' . $this->options['reply_to'];
}
if (!is_array($message)) {
$headers[] = 'Content-Type: text/html;charset=UTF-8';
$body = $message;
} else {
// Only html is present?
if (!empty($message['html'])) {
$headers[] = 'Content-Type: text/html;charset=UTF-8';
$body = $message['html'];
} else {
if (!empty($message['text'])) {
$headers[] = 'Content-Type: text/plain;charset=UTF-8';
$this->mailer->IsHTML(false);
$body = $message['text'];
}
}
}
$r = wp_mail($to, $subject, $body, $headers);
if (!$r) {
$last_error = error_get_last();
if (is_array($last_error)) {
$this->mail_last_error = $last_error['message'];
}
}
return $r;
}
// Simple message is asumed to be html
if (!is_array($message)) {
$this->mailer->IsHTML(true);
$this->mailer->Body = $message;
} else {
// Only html is present?
if (empty($message['text'])) {
$this->mailer->IsHTML(true);
$this->mailer->Body = $message['html'];
} else {
if (empty($message['html'])) {
$this->mailer->IsHTML(false);
$this->mailer->Body = $message['text'];
} else {
$this->mailer->IsHTML(true);
$this->mailer->Body = $message['html'];
$this->mailer->AltBody = $message['text'];
}
}
}
$this->mailer->Subject = $subject;
$this->mailer->ClearCustomHeaders();
if (!empty($headers)) {
foreach ($headers as $key => $value) {
$this->mailer->AddCustomHeader($key . ': ' . $value);
}
}
$this->mailer->ClearAddresses();
$this->mailer->AddAddress($to);
$this->mailer->Send();
if ($this->mailer->IsError()) {
//.........这里部分代码省略.........