PHPmailer如何在空白的情况下从html表单输入发送两封电子邮件

时间:2018-07-19 06:37:40

标签: phpmailer

我正在从带有2个电子邮件地址输入的表单发送电子邮件,其中可以使用一个或两个都不使用。但是,当我将第二个留空时,我收到一条错误消息。我认为这是因为我没有验证第二个。但是,如果我添加代码以验证第二个代码,则不会发送任何电子邮件,因为它被中止了。我想我不了解如何执行此操作的概念。

  

致命错误:/var/www/html/PHPMailer/class.phpmailer.php:869中消息“无效地址:(addAnAddress cc):'的未捕获异常'phpmailerException”堆栈跟踪:#0 / var / www / html / PHPMailer / class.phpmailer.php(821):PHPMailer-> addOrEnqueueAnAddress('cc',``,'')#1 /var/www/html/innoedit.php(71):PHPMailer-> addCC(' ')#2 {main}在第869行的/var/www/html/PHPMailer/class.phpmailer.php中抛出

$mail = new PHPMailer(true);
  $mail->CharSet = 'utf-8';
  ini_set('default_charset', 'UTF-8');
  class phpmailerAppException extends phpmailerException {}
  try {
    $to = $responsiblepost;
    if(!PHPMailer::validateAddress($to)) {
      throw new phpmailerAppException("Email address " . $to . " is invalid -- aborting!");
    }

    $mail->SMTPOptions = array(
      'ssl' => array(
      'verify_peer' => false,
      'verify_peer_name' => false,
      'allow_self_signed' => true
      )
    );
$mail->isSMTP();
$mail->SMTPDebug  = 0;
$mail->Host       = "smtp.example.com";
$mail->Port       = "25";
$mail->SMTPSecure = "none";
$mail->SMTPAuth   = true;
$mail->Username   = "noreply@example.com";
$mail->Password   = "password";
$mail->addReplyTo("andrew@example.com");
$mail->setFrom("noreply@example.com");
$mail->addAddress($to); //from first <input>
$mail->addAddress($informedpost); //from second <input>
$mail->Subject  = "subject";
$body = "<html>...

0 个答案:

没有答案