pb电子邮件,多个电子邮件不想发送 - phpmailer

时间:2015-01-10 15:05:25

标签: php email phpmailer

我想知道你是否对这个问题有所了解,

我的数据库是utf8,我插入这些元素

test<test@test.com>, test1<test@test.com> by SEND_EXTRA_ORDER_EMAILS_TO

我使用Phpmailer

如果我这样做:

test<test@test.com> ==> does'nt work
test@test.com, test1@test.com ==> does'nt work
test<test@test.com>, test1<test1@test.com>  ==> does'nt work
test@test.com ==> 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<test@test.com>, test1<test@test.com>
  }

并在我的档案中:

SEND_EXTRA_ORDER_EMAILS_TO是test,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;
    }
  }

1 个答案:

答案 0 :(得分:0)

如果这是流行的PHPMailer https://github.com/PHPMailer/PHPMailer

你可以这样做:

$address = "test@test.com";
$mail->AddAddress($address, "John Doe");
$address = "test2@test2.com";
$mail->AddAddress($address, "John Smith");
$mail->SetFrom($from_email_address, $from_email_name);
$mail->Subject  = $email_subject;
$mail->send();

我希望你在寻找什么