本文整理汇总了PHP中Mail_RFC822::_splitAddresses方法的典型用法代码示例。如果您正苦于以下问题:PHP Mail_RFC822::_splitAddresses方法的具体用法?PHP Mail_RFC822::_splitAddresses怎么用?PHP Mail_RFC822::_splitAddresses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mail_RFC822
的用法示例。
在下文中一共展示了Mail_RFC822::_splitAddresses方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* Send an email message.
*
* @access public
* @param string $to Recipient email address
* @param string $from Sender email address
* @param string $subject Subject line for message
* @param string $body Message body
* @param string $replyTo Someone to reply to
*
* @return mixed PEAR error on error, boolean true otherwise
*/
public function send($to, $from, $subject, $body, $replyTo = null)
{
global $logger;
// Validate sender and recipient
$validator = new Mail_RFC822();
//Allow the to address to be split
$validator->_splitAddresses($to);
foreach ($validator->addresses as $tmpAddress) {
if (!$validator->isValidInetAddress($tmpAddress['address'])) {
return new PEAR_Error('Invalid Recipient Email Address ' . $tmpAddress);
}
}
if (!$validator->isValidInetAddress($from)) {
return new PEAR_Error('Invalid Sender Email Address');
}
$headers = array('To' => $to, 'Subject' => $subject, 'Date' => date('D, d M Y H:i:s O'), 'Content-Type' => 'text/plain; charset="UTF-8"');
if (isset($this->settings['fromAddress'])) {
$logger->log("Overriding From address, using " . $this->settings['fromAddress'], PEAR_LOG_INFO);
$headers['From'] = $this->settings['fromAddress'];
$headers['Reply-To'] = $from;
} else {
$headers['From'] = $from;
}
if ($replyTo != null) {
$headers['Reply-To'] = $replyTo;
}
// Get mail object
if ($this->settings['host'] != false) {
$mailFactory = new Mail();
$mail =& $mailFactory->factory('smtp', $this->settings);
if (PEAR_Singleton::isError($mail)) {
return $mail;
}
// Send message
return $mail->send($to, $headers, $body);
} else {
//Mail to false just emits the information to screen
$formattedMail = '';
foreach ($headers as $key => $header) {
$formattedMail .= $key . ': ' . $header . '<br />';
}
$formattedMail .= $body;
$logger->log("Sending e-mail", PEAR_LOG_INFO);
$logger->log("From = {$from}", PEAR_LOG_INFO);
$logger->log("To = {$to}", PEAR_LOG_INFO);
$logger->log($subject, PEAR_LOG_INFO);
$logger->log($formattedMail, PEAR_LOG_INFO);
return true;
}
}