php Send mail problem: Message sent, return to invalid address:

Source: Internet
Author: User
Tags php send mail

Why is there such a situation?


Reply to discussion (solution)

These are the custom prompts, specifically why, to look at the code. Follow the code below ...

Require_once Application_path. ' /models/class.phpmailer.php ';
Send mail
Class send_mail{

function Send_mail ($fromname, $subject, $content, $user _mail)
{
$mail = new Phpmailer (); Instantiation of
$mail->issmtp (); Enable SMTP
$mail->host = "smtp.163.com"; SMTP Server Sina Mailbox
$mail->port = 25; Mail Send port
$mail->smtpauth = true; Enable SMTP authentication
$mail->charset = "UTF-8"; Character
$mail->encoding = "base64"; Encoding method
$mail->username = "yzhjtx@163.com"; Your e-mail
$mail->password = "hjtx123456"; Your password.
$mail->subject = $subject; Message header
$mail->from = "yzhjtx@163.com"; Sender address (that is, your mailbox)
$mail->fromname = $fromname; Sender's name
$address = "$user _mail";//Recipient Email
$mail->addaddress ("$address");//Add recipient address, nickname
$mail->ishtml (TRUE); Support HTML format content
$emailtype = "HTML"; Letter type, text: text; Web page: HTML
$mail->body = $content;//message content
if (! $mail->send ()) {
return false;
} else {
return true; Sent successfully
}
}
}

These are the custom prompts, specifically why, to look at the code. Follow the code below ...


The code to send the message:
Require_once Application_path. ' /models/class.phpmailer.php ';
Send mail
Class send_mail{

function Send_mail ($fromname, $subject, $content, $user _mail)
{
$mail = new Phpmailer (); Instantiation of
$mail->issmtp (); Enable SMTP
$mail->host = "smtp.163.com"; SMTP Server Sina Mailbox
$mail->port = 25; Mail Send port
$mail->smtpauth = true; Enable SMTP authentication
$mail->charset = "UTF-8"; Character
$mail->encoding = "base64"; Encoding method
$mail->username = "yzhjtx@163.com"; Your e-mail
$mail->password = "hjtx123456"; Your password.
$mail->subject = $subject; Message header
$mail->from = "yzhjtx@163.com"; Sender address (that is, your mailbox)
$mail->fromname = $fromname; Sender's name
$address = "$user _mail";//Recipient Email
$mail->addaddress ("$address");//Add recipient address, nickname
$mail->ishtml (TRUE); Support HTML format content
$emailtype = "HTML"; Letter type, text: text; Web page: HTML
$mail->body = $content;//message content
if (! $mail->send ()) {
return false;
} else {
return true; Sent successfully
}
}
}

Invalid address is not valid

Invalid address is not valid


But the Mail has been sent out, my mailbox received a new mail

You see class.phpmailer.php there is no Invalid address hint, if not, the whole project search.
Take a closer look and see where this information is, and know why. Basic Debugging Method!

Look at the tip is email is not correct.

If you can receive the message, but the mail server returns the prompt, you need to check what state the class.phpmailer.php is receiving.

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;
}
...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.