Home  >  Article  >  Backend Development  >  PHP发送邮件问题:邮件已发送,返回Invalid address:

PHP发送邮件问题:邮件已发送,返回Invalid address:

WBOY
WBOYOriginal
2016-06-23 13:48:563330browse

如图所示:
为什么会出现这样的情况?


回复讨论(解决方案)

这些都是自定义提示,具体为什么,要看代码。跟踪下代码。。。

require_once APPLICATION_PATH.'/models/class.phpmailer.php';
//发送邮件
class Send_Mail{
    
    function send_mail($fromname,$subject,$content,$user_mail)
    {
        $mail = new PHPMailer(); //实例化
        $mail->IsSMTP(); // 启用SMTP
        $mail->Host = "smtp.163.com"; //SMTP服务器 新浪邮箱
        $mail->Port = 25;  //邮件发送端口
        $mail->SMTPAuth   = true;  //启用SMTP认证
        $mail->CharSet  = "UTF-8"; //字符集
        $mail->Encoding = "base64"; //编码方式
        $mail->Username = "yzhjtx@163.com";  //你的邮箱
        $mail->Password = "hjtx123456";  //你的密码
        $mail->Subject = $subject; //邮件标题
        $mail->From = "yzhjtx@163.com";  //发件人地址(也就是你的邮箱)
        $mail->FromName = $fromname;  //发件人姓名
        $address = "$user_mail";//收件人email
        $mail->AddAddress("$address");//添加收件人地址,昵称
        $mail->IsHTML(true); //支持html格式内容
        $emailtype = "HTML"; //信件类型,文本:text;网页:HTML
        $mail->Body = $content;//邮件内容
        if(!$mail->Send()) {
            return false;
        } else {
            return true; //发送成功
        }
    }
}

这些都是自定义提示,具体为什么,要看代码。跟踪下代码。。。


发邮件的代码:
require_once APPLICATION_PATH.'/models/class.phpmailer.php';
//发送邮件
class Send_Mail{
    
    function send_mail($fromname,$subject,$content,$user_mail)
    {
        $mail = new PHPMailer(); //实例化
        $mail->IsSMTP(); // 启用SMTP
        $mail->Host = "smtp.163.com"; //SMTP服务器 新浪邮箱
        $mail->Port = 25;  //邮件发送端口
        $mail->SMTPAuth   = true;  //启用SMTP认证
        $mail->CharSet  = "UTF-8"; //字符集
        $mail->Encoding = "base64"; //编码方式
        $mail->Username = "yzhjtx@163.com";  //你的邮箱
        $mail->Password = "hjtx123456";  //你的密码
        $mail->Subject = $subject; //邮件标题
        $mail->From = "yzhjtx@163.com";  //发件人地址(也就是你的邮箱)
        $mail->FromName = $fromname;  //发件人姓名
        $address = "$user_mail";//收件人email
        $mail->AddAddress("$address");//添加收件人地址,昵称
        $mail->IsHTML(true); //支持html格式内容
        $emailtype = "HTML"; //信件类型,文本:text;网页:HTML
        $mail->Body = $content;//邮件内容
        if(!$mail->Send()) {
            return false;
        } else {
            return true; //发送成功
        }
    }
}

Invalid address 无效的地址

Invalid address 无效的地址


但是邮件已经发出去了,我的邮箱收到了新邮件

你看看class.phpmailer.php里有没有 Invalid address的提示,如果没有,全项目搜索一下。
顺藤摸瓜,看看哪里出了这样的信息,就知道为什么了。基本调试方法!

看提示是email不正确。

如果能接收到邮件,但邮件服务器却返回这个提示,则需要检查class.phpmailer.php接受到的是什么状态。

  public function AddAddress($address, $name = '') {
    return $this->AddAnAddress('to', $address, $name);
  }

  private function AddAnAddress($kind, $address, $name = '') {
    if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
      echo 'Invalid recipient array: ' . kind;
      return false;
    }
    $address = trim($address);
    $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
    if (!self::ValidateAddress($address)) {
      $this->SetError($this->Lang('invalid_address').': '. $address);
      if ($this->exceptions) {
        throw new phpmailerException($this->Lang('invalid_address').': '.$address);
      }
       echo $this->Lang('invalid_address').': '.$address;
      return false;
    }
 ...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn