2015-01-10 2 views
-1

Я хочу знать, если у вас есть идея по поводу этой проблемы,рите электронную почту, электронная почта множественного does'nt хочет отправленный - PHPMailer

Моей база данных utf8 и внутри я вставить эти элементы

test<[email protected]>, test1<[email protected]> by SEND_EXTRA_ORDER_EMAILS_TO 

I использовать PHPMailer

Если я Fo, что:

test<[email protected]> ==> does'nt work 
[email protected], [email protected] ==> does'nt work 
test<[email protected]>, test1<[email protected]> ==> does'nt work 
[email protected] ==> work 

Спасибо

моя функция

function osc_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) { 
    if (SEND_EMAILS != 'true') return false; 

// Instantiate a new mail object 
    $message = new email(array('X-Mailer: ClicShopping Mailer')); 

    // Build the text version 
    $text = strip_tags($email_text); 
    if (EMAIL_USE_HTML == 'true') { 
     $message->add_html($email_text, $text); 
    } else { 
     $message->add_text($text); 
    } 

    // Send message 
    $message->build_message(); 
    $message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject); 

    var_dump($to_email_address);// ====> See test<[email protected]>, test1<[email protected]> 
    } 

и в моем файле:

SEND_EXTRA_ORDER_EMAILS_TO является тест, test1

if (SEND_EXTRA_ORDER_EMAILS_TO != '') { 
    $email_text_subject = stripslashes(EMAIL_TEXT_SUBJECT); 
    $email_text_subject = html_entity_decode($email_text_subject); 
    osc_mail('', SEND_EXTRA_ORDER_EMAILS_TO, $email_text_subject, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS); 
    } 

мой класс:

$phpMail = new PHPMailer(); 

    class email { 
    var $html; 
    var $text; 
    var $html_text; 
    var $lf; 
    var $debug = 0; 
    var $debug_output = 'error_log'; 

    function email($headers = '') { 
     global $phpMail; 

     $phpMail->XMailer = 'ClicShopping'; 
     $phpMail->SMTPDebug = $this->debug; 
     $phpMail->Debugoutput = $this->debug_output; 
     $phpMail->CharSet = CHARSET; 
     $phpMail->WordWrap = 998; 

     if (EMAIL_TRANSPORT == 'smtp' || EMAIL_TRANSPORT == 'gmail') { 
     $phpMail->IsSMTP(); 

     $phpMail->Port = EMAIL_SMTP_PORT; 
     if (EMAIL_SMTP_SECURE !== 'no') { 
      $phpMail->SMTPSecure = EMAIL_SMTP_SECURE; 
     } 

     $phpMail->Host = EMAIL_SMTP_HOSTS; 
     $phpMail->SMTPAuth = EMAIL_SMTP_AUTHENTICATION; 

     $phpMail->Username = EMAIL_SMTP_USER; 
     $phpMail->Password = EMAIL_SMTP_PASSWORD; 

     } else { 
     $phpMail->isSendmail(); 
     } 

     if (EMAIL_LINEFEED == 'CRLF') { 
     $this->lf = "\r\n"; 
     } else { 
     $this->lf = "\n"; 
     } 
    } 

    function add_text($text = '') { 
     global $phpMail; 

     $phpMail->IsHTML(false); 
     $this->text = osc_convert_linefeeds(array("\r\n", "\n", "\r"), $this->lf, $text); 
    } 

/** 
* Adds a html part to the mail. 
* Also replaces image names with 
* content-id's. 
*/ 

    function add_html($html, $text = NULL, $images_dir = NULL) { 
     global $phpMail; 

     $phpMail->IsHTML(true); 
     $this->html = osc_convert_linefeeds(array("\r\n", "\n", "\r"), '<br />', $html); 
     $this->html_text = osc_convert_linefeeds(array("\r\n", "\n", "\r"), $this->lf, $text); 

     if (isset($images_dir)) $this->html = $phpMail->msgHTML($this->html, $images_dir); 
    } 

/** 
* Adds a html part to the mail. 
* Also replaces image names with 
* content-id's. 
*/ 

// FCKeditor 
    function add_html_fckeditor($html, $text = NULL, $images_dir = NULL) { 
     global $phpMail; 

     $phpMail->IsHTML(true); 

     $this->html = osc_convert_linefeeds(array("\r\n", "\n", "\r"), '', $html); 
     $this->html_text = osc_convert_linefeeds(array("\r\n", "\n", "\r"), $this->lf, $text); 

     if (isset($images_dir)) $this->html = $phpMail->msgHTML($this->html, $images_dir); 
    } 


    function add_attachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment') { 
     global $phpMail; 

     $phpMail->AddAttachment($path, $name, $encoding, $type, $disposition); 
    } 

    function build_message() { 
     //out of work function 
    } 

/** 
* Sends the mail. 
*/ 

    function send($to_name, $to_addr, $from_name, $from_addr, $subject = '', $reply_to = false) { 
     global $phpMail; 

     if ((strstr($to_name, "\n") != false) || (strstr($to_name, "\r") != false)) { 
     return false; 
     } 

     if ((strstr($to_addr, "\n") != false) || (strstr($to_addr, "\r") != false)) { 
     return false; 
     } 

     if ((strstr($subject, "\n") != false) || (strstr($subject, "\r") != false)) { 
     return false; 
     } 

     if ((strstr($from_name, "\n") != false) || (strstr($from_name, "\r") != false)) { 
     return false; 
     } 

     if ((strstr($from_addr, "\n") != false) || (strstr($from_addr, "\r") != false)) { 
     return false; 
     } 

     $phpMail->From = $from_addr; 
     $phpMail->FromName = $from_name; 
     $phpMail->AddAddress($to_addr, $to_name); 

     if ($reply_to) { 
     $phpMail->AddReplyTo(EMAIL_SMTP_REPLYTO, STORE_NAME); 
     } else { 
     $phpMail->AddReplyTo($from_addr, $from_name); 
     } 

     $phpMail->Subject = $subject; 

     if (!empty($this->html)) { 
     $phpMail->Body = $this->html; 
     $phpMail->AltBody = $this->html_text; 
     } else { 
     $phpMail->Body = $this->text; 
     } 

     if (EMAIL_TRANSPORT == 'smtp' || EMAIL_TRANSPORT == 'gmail') { 
     $phpMail->IsSMTP(); 

     $phpMail->Port = EMAIL_SMTP_PORT; 
     if (EMAIL_SMTP_SECURE !== 'no') { 
      $phpMail->SMTPSecure = EMAIL_SMTP_SECURE; 
     } 

     $phpMail->Host = EMAIL_SMTP_HOSTS; 
     $phpMail->SMTPAuth = EMAIL_SMTP_AUTHENTICATION; 

     $phpMail->Username = EMAIL_SMTP_USER; 
     $phpMail->Password = EMAIL_SMTP_PASSWORD; 

     } else { 
     $phpMail->isSendmail(); 
     } 

     $error = false; 
     if (!$phpMail->Send()) { 
     $error = true; 
     } 

     $phpMail->clearAddresses(); 
     $phpMail->clearAttachments(); 

     if ($error == true) { 
     return false; 
     } 

     return true; 
    } 
    } 
+0

http://stackoverflow.com/questions/1770765/phpmailer-addaddress – Sithu

+0

Вот некоторые довольно ужасный код , Если вы собираетесь написать обертку, по крайней мере используйте ее для упрощения использования, не делайте ее более сложной, игнорируйте многие встроенные функции, вводите ненужные глобальные переменные и добавляйте бессмысленные поломки. Если вы хотите добавить несколько адресов, просто вызовите 'addAddress()' для каждого адреса, который вы хотите добавить. – Synchro

ответ

0

если это популярный PHPMailer https://github.com/PHPMailer/PHPMailer

Вы могли бы просто сделать:

$address = "[email protected]"; 
$mail->AddAddress($address, "John Doe"); 
$address = "[email protected]"; 
$mail->AddAddress($address, "John Smith"); 
$mail->SetFrom($from_email_address, $from_email_name); 
$mail->Subject = $email_subject; 
$mail->send(); 

Я надеюсь, что это то, что вы ищете

Смежные вопросы