本文整理汇总了PHP中Mail_RFC822::parseAddressList方法的典型用法代码示例。如果您正苦于以下问题:PHP Mail_RFC822::parseAddressList方法的具体用法?PHP Mail_RFC822::parseAddressList怎么用?PHP Mail_RFC822::parseAddressList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mail_RFC822
的用法示例。
在下文中一共展示了Mail_RFC822::parseAddressList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionParse
public static function actionParse()
{
$tolist = 'apple@beta.com,
Michael Ferranti <ferranti.michael@gmail.com>
"Jeff Reifman" <jeff@reifman.org>, <apple@app2.com>,jeff <jeff@smith.com>';
//Yii::import('ext.Mail_RFC822');
include 'Mail/RFC822.php';
$parser = new Mail_RFC822();
// replace the backslash quotes
$tolist = str_replace('\\"', '"', $tolist);
// split the elements by line and by comma
$to_email_array = preg_split("(\r|\n|,)", $tolist, -1, PREG_SPLIT_NO_EMPTY);
$num_emails = count($to_email_array);
echo $num_emails;
for ($count = 0; $count < $num_emails && $count <= 500; $count++) {
$toAddress = trim($to_email_array[$count]);
if ($toAddress != '') {
$addresses = $parser->parseAddressList('my group:' . $toAddress, 'bushsucks.com', false, true);
var_dump($addresses);
lb();
}
//$toAddress=$addresses[0]->mailbox.'@'.$addresses[0]->host;
//if ($this->utilObj->checkEmail($toAddress)) {
// store it or send it or whatever you want to do
//}
}
}
示例2: get_mail_addr_array
/**
* アドレスの羅列から名前とメールアドレスの連想配列を取得する
*
* @param $str メールヘッダに含まれるメールアドレスの羅列
* @param メールアドレスの配列
*/
static function get_mail_addr_array($str)
{
// メールアドレスリストとしてparse
$mail_addr_obj_array = Mail_RFC822::parseAddressList($str);
// メールアドレスを格納する配列
$mail_addr_array = array();
foreach ($mail_addr_obj_array as $mail_addr_obj) {
// メールアドレス
$mail_addr = $mail_addr_obj->mailbox . '@' . $mail_addr_obj->host;
array_push($mail_addr_array, $mail_addr);
}
return $mail_addr_array;
}
示例3: valid_email
function valid_email($email)
{
$emailObjects = Mail_RFC822::parseAddressList($email);
if (PEAR::isError($emailObjects)) {
return false;
}
$emailObject = $emailObjects[0];
$email = $emailObject->mailbox . '@' . $emailObject->host;
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
return false;
} else {
return true;
}
}
示例4: parseAddressList
function parseAddressList($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
{
if (!isset($this) || !isset($this->mailRFC822)) {
$obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit);
return $obj->parseAddressList();
}
if (isset($address)) {
$this->address = $address;
}
if (isset($default_domain)) {
$this->default_domain = $default_domain;
}
if (isset($nest_groups)) {
$this->nestGroups = $nest_groups;
}
if (isset($validate)) {
$this->validate = $validate;
}
if (isset($limit)) {
$this->limit = $limit;
}
$this->structure = array();
$this->addresses = array();
$this->error = null;
$this->index = null;
$this->address = preg_replace('/\\r?\\n/', "\r\n", $this->address);
$this->address = preg_replace('/\\r\\n(\\t| )+/', ' ', $this->address);
while ($this->address = $this->_splitAddresses($this->address)) {
}
if ($this->address === false || isset($this->error)) {
require_once 'PEAR.php';
return PEAR::raiseError($this->error);
}
foreach ($this->addresses as $address) {
$valid = $this->_validateAddress($address);
if ($valid === false || isset($this->error)) {
require_once 'PEAR.php';
return PEAR::raiseError($this->error);
}
if (!$this->nestGroups) {
$this->structure = array_merge($this->structure, $valid);
} else {
$this->structure[] = $valid;
}
}
return $this->structure;
}
开发者ID:MMU-TWT-Class-Oct-2015,项目名称:G10B_Sales_of_Point_System_for_Video_and_Audio_shop,代码行数:47,代码来源:RFC822.php
示例5: updateOrCreateEmail
function updateOrCreateEmail($part = '', $opts, $cm = false)
{
// DB_DataObject::debugLevel(1);
$template_name = preg_replace('/\\.[a-z]+$/i', '', basename($opts['file']));
if (!file_exists($opts['file'])) {
$this->jerr("file does not exist : " . $opts['file']);
}
if (!empty($opts['master']) && !file_exists($opts['master'])) {
$this->jerr("master file does not exist : " . $opts['master']);
}
if (empty($cm)) {
$cm = DB_dataObject::factory('core_email');
$ret = $cm->get('name', $template_name);
if ($ret && empty($opts['update'])) {
$this->jerr("use --update 1 to update the template..");
}
}
$mailtext = file_get_contents($opts['file']);
if (!empty($opts['master'])) {
$body = $mailtext;
$mailtext = file_get_contents($opts['master']);
$mailtext = str_replace('{outputBody():h}', $body, $mailtext);
}
require_once 'Mail/mimeDecode.php';
require_once 'Mail/RFC822.php';
$decoder = new Mail_mimeDecode($mailtext);
$parts = $decoder->getSendArray();
if (is_a($parts, 'PEAR_Error')) {
echo $parts->toString() . "\n";
exit;
}
$headers = $parts[1];
$from = new Mail_RFC822();
$from_str = $from->parseAddressList($headers['From']);
$from_name = trim($from_str[0]->personal, '"');
$from_email = $from_str[0]->mailbox . '@' . $from_str[0]->host;
if ($cm->id) {
$cc = clone $cm;
$cm->setFrom(array('bodytext' => $parts[2], 'updated_dt' => date('Y-m-d H:i:s')));
$cm->update($cc);
} else {
$cm->setFrom(array('from_name' => $from_name, 'from_email' => $from_email, 'subject' => $headers['Subject'], 'name' => $template_name, 'bodytext' => $parts[2], 'updated_dt' => date('Y-m-d H:i:s'), 'created_dt' => date('Y-m-d H:i:s')));
$cm->insert();
}
return $cm;
}
示例6: register
function register(&$data)
{
$session = Session::singletone();
if (empty($data['user_login'])) {
throw new Exception2("Nie mo¿na zarejestrowaæ konta", "Musisz podaæ login.");
}
if (empty($data['user_pass1']) || empty($data['user_pass2'])) {
throw new Exception2("Nie mo¿na zarejestrowaæ konta", "Has³o nie mo¿e byæ puste.");
}
if (empty($data['user_email'])) {
throw new Exception2("Nie mo¿na zarejestrowaæ konta", "Musisz podaæ email.");
}
$addr = Mail_RFC822::parseAddressList($data['user_email'], "");
if (empty($addr)) {
throw new Exception2("Nie mo¿na zarejestrowaæ konta", "Podany adres email jest nieprawid³owy.");
}
if ($data['user_pass1'] != $data['user_pass2']) {
throw new Exception2("Nie mo¿na zarejestrowaæ konta", "Podane has³a ró¿ni± siê");
}
$user_login = trim($data['user_login']);
$user_pass1 = $data['user_pass1'];
$user_pass2 = $data['user_pass2'];
$user_email = trim($data['user_email']);
$this->_dbo = DB_DataObject::Factory('phph_users');
if (PEAR::isError($this->_dbo)) {
throw new Exception2(_INTERNAL_ERROR, $this->_dbo->getMessage());
}
$r = $this->_dbo->get('user_login', $user_login);
if (PEAR::isError($r)) {
throw new Exception2(_INTERNAL_ERROR, $r->getMessage());
}
if ($r != 0) {
throw new Exception2("Nie mo¿na zarejestrowaæ konta", "Podany login jest ju¿ zajêty.");
}
$this->_dbo->user_login = $user_login;
$this->_dbo->user_pass = md5($user_pass1);
$this->_dbo->user_email = $user_email;
$this->_dbo->user_registered = time();
$this->_dbo->user_activation = md5(uniqid($user_login));
$r = $this->_dbo->insert();
if (PEAR::isError($r)) {
throw new Exception2(_INTERNAL_ERROR, $r->getMessage());
}
return $r;
}
示例7: valid_email
function valid_email($email)
{
$emailObjects = Mail_RFC822::parseAddressList($email);
if (PEAR::isError($emailObjects)) {
return false;
}
// Get the mailbox and host parts of the email object
$mailbox = $emailObjects[0]->mailbox;
$host = $emailObjects[0]->host;
// Make sure the mailbox and host parts aren't too long
if (strlen($mailbox) > 64) {
return false;
}
if (strlen($host) > 255) {
return false;
}
// Validate the mailbox
$atom = '[[:alnum:]_!#$%&\'*+\\/=?^`{|}~-]+';
$dotatom = '(\\.' . $atom . ')*';
$address = '(^' . $atom . $dotatom . '$)';
$char = '([^\\\\"])';
$esc = '(\\\\[\\\\"])';
$text = '(' . $char . '|' . $esc . ')+';
$quoted = '(^"' . $text . '"$)';
$localPart = '/' . $address . '|' . $quoted . '/';
$localMatch = preg_match($localPart, $mailbox);
if ($localMatch === false || $localMatch != 1) {
return false;
}
// Validate the host
$hostname = '([[:alnum:]]([-[:alnum:]]{0,62}[[:alnum:]])?)';
$hostnames = '(' . $hostname . '(\\.' . $hostname . ')*)';
$top = '\\.[[:alnum:]]{2,6}';
$domainPart = '/^' . $hostnames . $top . '$/';
$domainMatch = preg_match($domainPart, $host);
if ($domainMatch === false || $domainMatch != 1) {
return false;
}
return true;
}
示例8: getCcAddressList
function getCcAddressList()
{
return $this->struct->headers['cc'] ? Mail_RFC822::parseAddressList($this->struct->headers['cc']) : null;
}
示例9: array
}
//exit();
//get all the destined addresses from to,cc,bcc into the array $var_toaddress
//do check for duplicates and insert all valid addresses to $var_toaddress array
$var_toaddress = array();
for ($j = 0; $j < 3; $j++) {
$structure = "";
switch ($j) {
case 0:
$structure = Mail_RFC822::parseAddressList($mimedecoder->_mailheader->_headerto, 'example.com', true);
break;
case 1:
$structure = Mail_RFC822::parseAddressList($mimedecoder->_mailheader->_headercc, 'example.com', true);
break;
case 2:
$structure = Mail_RFC822::parseAddressList($mimedecoder->_mailheader->_headerbcc, 'example.com', true);
break;
}
$cnt = count($structure);
for ($i = 0; $i < $cnt; $i++) {
$var_temp = $structure[$i]->mailbox . "@" . strtolower($structure[$i]->host);
if ($structure[$i]->mailbox != "" && !isset($var_toaddress[$var_temp])) {
$var_toaddress[$var_temp] = $structure[$i]->mailbox;
}
}
}
//print_r($var_toaddress);
/*
*Case-sensitivity for isset - it is case sensitive
*so same email addresses with different case may create two tickets
*se we convert all domain names to lower case here
示例10: SendMail
function SendMail($rfc822, $forward = false, $reply = false, $parent = false)
{
debugLog("IMAP-SendMail: " . $rfc822 . "for: {$forward} reply: {$reply} parent: {$parent}");
$mobj = new Mail_mimeDecode($rfc822);
$message = $mobj->decode(array('decode_headers' => false, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\n", 'charset' => 'utf-8'));
$toaddr = $ccaddr = $bccaddr = "";
if (isset($message->headers["to"])) {
$toaddr = $this->parseAddr(Mail_RFC822::parseAddressList($message->headers["to"]));
}
if (isset($message->headers["cc"])) {
$ccaddr = $this->parseAddr(Mail_RFC822::parseAddressList($message->headers["cc"]));
}
if (isset($message->headers["bcc"])) {
$bccaddr = $this->parseAddr(Mail_RFC822::parseAddressList($message->headers["bcc"]));
}
// save some headers when forwarding mails (content type & transfer-encoding)
$headers = "";
$forward_h_ct = "";
$forward_h_cte = "";
$use_orgbody = false;
// clean up the transmitted headers
// remove default headers because we are using imap_mail
$changedfrom = false;
$returnPathSet = false;
$body_base64 = false;
$org_charset = "";
foreach ($message->headers as $k => $v) {
if ($k == "subject" || $k == "to" || $k == "cc" || $k == "bcc") {
continue;
}
if ($k == "content-type") {
// save the original content-type header for the body part when forwarding
if ($forward) {
$forward_h_ct = $v;
continue;
}
// set charset always to utf-8
$org_charset = $v;
$v = preg_replace("/charset=([A-Za-z0-9-\"']+)/", "charset=\"utf-8\"", $v);
}
if ($k == "content-transfer-encoding") {
// if the content was base64 encoded, encode the body again when sending
if (trim($v) == "base64") {
$body_base64 = true;
}
// save the original encoding header for the body part when forwarding
if ($forward) {
$forward_h_cte = $v;
continue;
}
}
// if the message is a multipart message, then we should use the sent body
if (!$forward && $k == "content-type" && preg_match("/multipart/i", $v)) {
$use_orgbody = true;
}
// check if "from"-header is set
if ($k == "from" && !trim($v) && IMAP_DEFAULTFROM) {
$changedfrom = true;
if (IMAP_DEFAULTFROM == 'username') {
$v = $this->_username;
} else {
if (IMAP_DEFAULTFROM == 'domain') {
$v = $this->_domain;
} else {
$v = $this->_username . IMAP_DEFAULTFROM;
}
}
}
// check if "Return-Path"-header is set
if ($k == "return-path") {
$returnPathSet = true;
if (!trim($v) && IMAP_DEFAULTFROM) {
if (IMAP_DEFAULTFROM == 'username') {
$v = $this->_username;
} else {
if (IMAP_DEFAULTFROM == 'domain') {
$v = $this->_domain;
} else {
$v = $this->_username . IMAP_DEFAULTFROM;
}
}
}
}
// all other headers stay
if ($headers) {
$headers .= "\n";
}
$headers .= ucfirst($k) . ": " . $v;
}
// set "From" header if not set on the device
if (IMAP_DEFAULTFROM && !$changedfrom) {
if (IMAP_DEFAULTFROM == 'username') {
$v = $this->_username;
} else {
if (IMAP_DEFAULTFROM == 'domain') {
$v = $this->_domain;
} else {
$v = $this->_username . IMAP_DEFAULTFROM;
}
}
//.........这里部分代码省略.........
示例11: send
/**
* Implements Mail_mail::send() function using php's built-in mail()
* command.
*
* @param mixed $recipients Either a comma-seperated list of recipients
* (RFC822 compliant), or an array of recipients,
* each RFC822 valid. This may contain recipients not
* specified in the headers, for Bcc:, resending
* messages, etc.
*
* @param array $headers The array of headers to send with the mail, in an
* associative array, where the array key is the
* header name (ie, 'Subject'), and the array value
* is the header value (ie, 'test'). The header
* produced from those values would be 'Subject:
* test'.
*
* @param string $body The full text of the message body, including any
* Mime parts, etc.
*
* @return mixed Returns true on success, or a PEAR_Error
* containing a descriptive error message on
* failure.
* @access public
*/
function send($recipients, $headers, $body)
{
// if we're passed an array of recipients, implode it.
if (is_array($recipients)) {
$recipients = implode(', ', $recipients);
}
// get the Subject out of the headers array so that we can
// pass it as a seperate argument to mail().
$subject = '';
if (isset($headers['Subject'])) {
$subject = $headers['Subject'];
unset($headers['Subject']);
}
// flatten the headers out.
list(, $text_headers) = Mail::prepareHeaders($headers);
include_once 'Mail/RFC822.php';
$addresses = Mail_RFC822::parseAddressList($headers['From'], 'localhost', false);
$from = $addresses[0]->mailbox . '@' . $addresses[0]->host;
return mail($recipients, $subject, $body, $text_headers, "-f" . $from . " " . $this->_params);
}
示例12: parseRecipients
/**
* Take a set of recipients and parse them, returning an array of
* bare addresses (forward paths) that can be passed to sendmail
* or an smtp server with the rcpt to: command.
*
* @param mixed Either a comma-seperated list of recipients
* (RFC822 compliant), or an array of recipients,
* each RFC822 valid.
*
* @return mixed An array of forward paths (bare addresses) or a PEAR_Error
* object if the address list could not be parsed.
* @access private
*/
function parseRecipients($recipients)
{
// if we're passed an array, assume addresses are valid and
// implode them before parsing.
if (is_array($recipients)) {
$recipients = implode(', ', $recipients);
}
// Parse recipients, leaving out all personal info. This is
// for smtp recipients, etc. All relevant personal information
// should already be in the headers.
$parser = new Mail_RFC822();
$addresses = $parser->parseAddressList($recipients, 'localhost', false);
// If parseAddressList() returned a PEAR_Error object, just return it.
//if (is_a($addresses, 'PEAR_Error')) {
if ($addresses === false) {
return $addresses;
}
$recipients = array();
if (is_array($addresses)) {
foreach ($addresses as $ob) {
$recipients[] = $ob->mailbox . '@' . $ob->host;
}
}
// Remove duplicated
$recipients = array_unique($recipients);
return $recipients;
}
示例13: send
/**
* Sends the mail.
*
* @param array $recipients Array of receipients to send the mail to
* @param string $type How to send the mail ('mail' or 'sendmail' or 'smtp')
* @return mixed
*/
public function send($recipients, $type = 'mail')
{
if (!defined('CRLF')) {
$this->setCRLF(($type == 'mail' or $type == 'sendmail') ? "\n" : "\r\n");
}
$this->build();
switch ($type) {
case 'mail':
$subject = '';
if (!empty($this->headers['Subject'])) {
$subject = $this->encodeHeader($this->headers['Subject'], $this->build_params['head_charset']);
unset($this->headers['Subject']);
}
// Get flat representation of headers
foreach ($this->headers as $name => $value) {
$headers[] = $name . ': ' . $this->encodeHeader($value, $this->build_params['head_charset']);
}
$to = $this->encodeHeader(implode(', ', $recipients), $this->build_params['head_charset']);
if (!empty($this->return_path)) {
$result = mail($to, $subject, $this->output, implode(CRLF, $headers), '-f' . $this->return_path);
} else {
$result = mail($to, $subject, $this->output, implode(CRLF, $headers));
}
// Reset the subject in case mail is resent
if ($subject !== '') {
$this->headers['Subject'] = $subject;
}
// Return
return $result;
break;
case 'sendmail':
// Get flat representation of headers
foreach ($this->headers as $name => $value) {
$headers[] = $name . ': ' . $this->encodeHeader($value, $this->build_params['head_charset']);
}
// Encode To:
$headers[] = 'To: ' . $this->encodeHeader(implode(', ', $recipients), $this->build_params['head_charset']);
// Get return path arg for sendmail command if necessary
$returnPath = '';
if (!empty($this->return_path)) {
$returnPath = '-f' . $this->return_path;
}
$pipe = popen($this->sendmail_path . " " . $returnPath, 'w');
$bytes = fputs($pipe, implode(CRLF, $headers) . CRLF . CRLF . $this->output);
$r = pclose($pipe);
return $r;
break;
case 'smtp':
require_once dirname(__FILE__) . '/smtp.php';
require_once dirname(__FILE__) . '/RFC822.php';
$smtp =& smtp::connect($this->smtp_params);
// Parse recipients argument for internet addresses
foreach ($recipients as $recipient) {
$addresses = Mail_RFC822::parseAddressList($recipient, $this->smtp_params['helo'], null, false);
foreach ($addresses as $address) {
$smtp_recipients[] = sprintf('%s@%s', $address->mailbox, $address->host);
}
}
unset($addresses);
// These are reused
unset($address);
// These are reused
// Get flat representation of headers, parsing
// Cc and Bcc as we go
foreach ($this->headers as $name => $value) {
if ($name == 'Cc' or $name == 'Bcc') {
$addresses = Mail_RFC822::parseAddressList($value, $this->smtp_params['helo'], null, false);
foreach ($addresses as $address) {
$smtp_recipients[] = sprintf('%s@%s', $address->mailbox, $address->host);
}
}
if ($name == 'Bcc') {
continue;
}
$headers[] = $name . ': ' . $this->encodeHeader($value, $this->build_params['head_charset']);
}
// Add To header based on $recipients argument
$headers[] = 'To: ' . $this->encodeHeader(implode(', ', $recipients), $this->build_params['head_charset']);
// Add headers to send_params
$send_params['headers'] = $headers;
$send_params['recipients'] = array_values(array_unique($smtp_recipients));
$send_params['body'] = $this->output;
// Setup return path
if (isset($this->return_path)) {
$send_params['from'] = $this->return_path;
} elseif (!empty($this->headers['From'])) {
$from = Mail_RFC822::parseAddressList($this->headers['From']);
$send_params['from'] = sprintf('%s@%s', $from[0]->mailbox, $from[0]->host);
} else {
$send_params['from'] = 'postmaster@' . $this->smtp_params['helo'];
}
// Send it
if (!$smtp->send($send_params)) {
//.........这里部分代码省略.........
示例14: parseAddressList
/**
* Starts the whole process. The address must either be set here
* or when creating the object. One or the other.
*
* @access public
* @param string $address The address(es) to validate.
* @param string $default_domain Default domain/host etc.
* @param boolean $nest_groups Whether to return the structure with groups nested for easier viewing.
* @param boolean $validate Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
*
* @return array A structured array of addresses.
*/
function parseAddressList($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
{
if (!isset($this->mailRFC822)) {
$obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit);
return $obj->parseAddressList();
}
if (isset($address)) {
$this->address = $address;
}
if (isset($default_domain)) {
$this->default_domain = $default_domain;
}
if (isset($nest_groups)) {
$this->nestGroups = $nest_groups;
}
if (isset($validate)) {
$this->validate = $validate;
}
if (isset($limit)) {
$this->limit = $limit;
}
$this->structure = array();
$this->addresses = array();
$this->error = null;
$this->index = null;
while ($this->address = $this->_splitAddresses($this->address)) {
continue;
}
if ($this->address === false || isset($this->error)) {
return $this->raiseError($this->error);
}
// Reset timer since large amounts of addresses can take a long time to
// get here
set_time_limit(30);
// Loop through all the addresses
for ($i = 0; $i < count($this->addresses); $i++) {
if (($return = $this->_validateAddress($this->addresses[$i])) === false || isset($this->error)) {
return $this->raiseError($this->error);
}
if (!$this->nestGroups) {
$this->structure = array_merge($this->structure, $return);
} else {
$this->structure[] = $return;
}
}
return $this->structure;
}
示例15: parseRecipients
/**
* Take a set of recipients and parse them, returning an array of
* bare addresses (forward paths) that can be passed to sendmail
* or an smtp server with the rcpt to: command.
*
* @param mixed Either a comma-seperated list of recipients
* (RFC822 compliant), or an array of recipients,
* each RFC822 valid.
*
* @return array An array of forward paths (bare addresses).
* @access private
*/
function parseRecipients($recipients)
{
include_once 'Mail/RFC822.php';
// if we're passed an array, assume addresses are valid and
// implode them before parsing.
if (is_array($recipients)) {
$recipients = implode(', ', $recipients);
}
// Parse recipients, leaving out all personal info. This is
// for smtp recipients, etc. All relevant personal information
// should already be in the headers.
$addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false);
$recipients = array();
if (is_array($addresses)) {
foreach ($addresses as $ob) {
$recipients[] = $ob->mailbox . '@' . $ob->host;
}
}
return $recipients;
}