本文整理汇总了PHP中EmailMessage::GetBody方法的典型用法代码示例。如果您正苦于以下问题:PHP EmailMessage::GetBody方法的具体用法?PHP EmailMessage::GetBody怎么用?PHP EmailMessage::GetBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EmailMessage
的用法示例。
在下文中一共展示了EmailMessage::GetBody方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Send
/**
* Send the message. If MAILER_RESULT_FAIL is returned, use GetErrors() to
* determine the problem.
*
* @param EmailMessage $message
* @return int results of operation (MAILER_RESULT_OK | MAILER_RESULT_FAIL)
*/
function Send($message)
{
$mailer = new PHPMailer();
// this prevents problems with phpmailer not being able to locate the language path
$mailer->SetLanguage("en", $this->LangPath);
$mailer->From = $message->From->Email;
$mailer->FromName = $message->From->RealName;
if ($message->ReplyTo) {
$mailer->AddReplyTo($message->ReplyTo->Email, $message->ReplyTo->RealName);
}
$mailer->Subject = $message->GetSubject();
$mailer->Body = $this->FixBareLB($message->GetBody());
$mailer->ContentType = $message->Format == MESSAGE_FORMAT_TEXT ? "text/plain" : "text/html";
$mailer->Mailer = strtolower($this->Method);
$mailer->Host = $this->Path;
$mailer->Sendmail = $this->Path;
// use authentication if necessary
if ($this->AuthUsername) {
$mailer->SMTPAuth = true;
$mailer->Username = $this->AuthUsername;
$mailer->Password = $this->AuthPassword;
}
// if custom headers are to be provided, include them in the message
foreach ($message->Headers as $header_key => $header_val) {
$mailer->AddCustomHeader($header_key . ': ' . $header_val);
}
if ($message->Sender) {
$this->_log[] = "Adding Sender " . $message->Sender;
// phpmailer accepts this but it seems to not work consistently..?
// $mailer->Sender = $message->Sender;
// instead add the dang headers ourselves
$mailer->AddCustomHeader("Sender: " . $message->Sender);
$mailer->AddCustomHeader("Return-Path: " . $message->Sender);
}
if (!$this->IsValid($mailer->From)) {
$this->_errors[] = "Sender '" . $mailer->From . "' is not a valid email address.";
return MAILER_RESULT_FAIL;
}
// add the recipients
foreach ($message->Recipients as $recipient) {
$this->_log[] = "Adding Recipient " . $recipient->RealName . " [" . $recipient->Email . "]";
if (!$this->IsValid($recipient->Email)) {
$this->_errors[] = "Recipient '" . $recipient->Email . "' is not a valid email address.";
return MAILER_RESULT_FAIL;
}
$mailer->AddAddress($recipient->Email, $recipient->RealName);
}
foreach ($message->CCRecipients as $recipient) {
$this->_log[] = "Adding CC Recipient " . $recipient->RealName . " [" . $recipient->Email . "]";
if (!$this->IsValid($recipient->Email)) {
$this->_errors[] = "CC Recipient '" . $recipient->Email . "' is not a valid email address.";
return MAILER_RESULT_FAIL;
}
$mailer->AddCC($recipient->Email, $recipient->RealName);
}
foreach ($message->BCCRecipients as $recipient) {
$this->_log[] = "Adding BCC Recipient " . $recipient->RealName . " [" . $recipient->Email . "]";
if (!$this->IsValid($recipient->Email)) {
$this->_errors[] = "BCC Recipient '" . $recipient->Email . "' is not a valid email address.";
return MAILER_RESULT_FAIL;
}
$mailer->AddBCC($recipient->Email, $recipient->RealName);
}
$result = MAILER_RESULT_OK;
$this->_log[] = "Sending message using " . $mailer->Mailer;
ob_start();
// buffer output because class.phpmailer.php Send() is chatty and writes to stdout
$fail = !$mailer->Send();
ob_end_clean();
// clear the buffer
if ($fail || $mailer->ErrorInfo) {
$result = MAILER_RESULT_FAIL;
$this->_errors[] = trim(str_replace(array('<p>', '</p>'), array(', ', ''), $mailer->ErrorInfo));
}
return $result;
}