本文整理匯總了PHP中EmailMessage::GetSubject方法的典型用法代碼示例。如果您正苦於以下問題:PHP EmailMessage::GetSubject方法的具體用法?PHP EmailMessage::GetSubject怎麽用?PHP EmailMessage::GetSubject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類EmailMessage
的用法示例。
在下文中一共展示了EmailMessage::GetSubject方法的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;
}