本文整理匯總了PHP中TYPO3\CMS\Core\Utility\MailUtility::parseAddresses方法的典型用法代碼示例。如果您正苦於以下問題:PHP MailUtility::parseAddresses方法的具體用法?PHP MailUtility::parseAddresses怎麽用?PHP MailUtility::parseAddresses使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類TYPO3\CMS\Core\Utility\MailUtility
的用法示例。
在下文中一共展示了MailUtility::parseAddresses方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sendNotifyEmail
/**
* Sends a notification email
*
* @param string $message The message content. If blank, no email is sent.
* @param string $recipients Comma list of recipient email addresses
* @param string $cc Email address of recipient of an extra mail. The same mail will be sent ONCE more; not using a CC header but sending twice.
* @param string $senderAddress "From" email address
* @param string $senderName Optional "From" name
* @param string $replyTo Optional "Reply-To" header email address.
* @return boolean Returns TRUE if sent
*/
public function sendNotifyEmail($message, $recipients, $cc, $senderAddress, $senderName = '', $replyTo = '')
{
$result = FALSE;
/** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
$mail = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
$senderName = trim($senderName);
$senderAddress = trim($senderAddress);
if ($senderName !== '' && $senderAddress !== '') {
$sender = array($senderAddress => $senderName);
} elseif ($senderAddress !== '') {
$sender = array($senderAddress);
} else {
$sender = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
}
$mail->setFrom($sender);
$parsedReplyTo = \TYPO3\CMS\Core\Utility\MailUtility::parseAddresses($replyTo);
if (count($parsedReplyTo) > 0) {
$mail->setReplyTo($parsedReplyTo);
}
$message = trim($message);
if ($message !== '') {
// First line is subject
$messageParts = explode(LF, $message, 2);
$subject = trim($messageParts[0]);
$plainMessage = trim($messageParts[1]);
$parsedRecipients = \TYPO3\CMS\Core\Utility\MailUtility::parseAddresses($recipients);
if (count($parsedRecipients) > 0) {
$mail->setTo($parsedRecipients)->setSubject($subject)->setBody($plainMessage);
$mail->send();
}
$parsedCc = \TYPO3\CMS\Core\Utility\MailUtility::parseAddresses($cc);
if (count($parsedCc) > 0) {
/** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
$mail = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
if (count($parsedReplyTo) > 0) {
$mail->setReplyTo($parsedReplyTo);
}
$mail->setFrom($sender)->setTo($parsedCc)->setSubject($subject)->setBody($plainMessage);
$mail->send();
}
$result = TRUE;
}
return $result;
}
示例2: sendNotifyEmail
/**
* Sends a notification email
*
* @param string $message The message content. If blank, no email is sent.
* @param string $recipients Comma list of recipient email addresses
* @param string $cc Email address of recipient of an extra mail. The same mail will be sent ONCE more; not using a CC header but sending twice.
* @param string $senderAddress "From" email address
* @param string $senderName Optional "From" name
* @param string $replyTo Optional "Reply-To" header email address.
* @return bool Returns TRUE if sent
*/
public function sendNotifyEmail($message, $recipients, $cc, $senderAddress, $senderName = '', $replyTo = '')
{
/** @var $mail MailMessage */
$mail = GeneralUtility::makeInstance(MailMessage::class);
$senderName = trim($senderName);
$senderAddress = trim($senderAddress);
if ($senderName !== '' && $senderAddress !== '') {
$sender = array($senderAddress => $senderName);
} elseif ($senderAddress !== '') {
$sender = array($senderAddress);
} else {
$sender = MailUtility::getSystemFrom();
}
$mail->setFrom($sender);
$parsedReplyTo = MailUtility::parseAddresses($replyTo);
if (!empty($parsedReplyTo)) {
$mail->setReplyTo($parsedReplyTo);
}
$message = trim($message);
if ($message !== '') {
// First line is subject
$messageParts = explode(LF, $message, 2);
$subject = trim($messageParts[0]);
$plainMessage = trim($messageParts[1]);
$parsedRecipients = MailUtility::parseAddresses($recipients);
if (!empty($parsedRecipients)) {
$mail->setTo($parsedRecipients)->setSubject($subject)->setBody($plainMessage);
$mail->send();
}
$parsedCc = MailUtility::parseAddresses($cc);
if (!empty($parsedCc)) {
/** @var $mail MailMessage */
$mail = GeneralUtility::makeInstance(MailMessage::class);
if (!empty($parsedReplyTo)) {
$mail->setReplyTo($parsedReplyTo);
}
$mail->setFrom($sender)->setTo($parsedCc)->setSubject($subject)->setBody($plainMessage);
$mail->send();
}
return true;
}
return false;
}
示例3: parseAddressesTest
/**
* @test
* @dataProvider parseAddressesProvider
*/
public function parseAddressesTest($source, $addressList)
{
$returnArray = \TYPO3\CMS\Core\Utility\MailUtility::parseAddresses($source);
$this->assertEquals($addressList, $returnArray);
}