PHP email sending problem: The email has been sent and Invalidaddress is returned:
:
Why is this happening?
Reply to discussion (solution)
These are all custom prompts. the specific reason depends on the code. Trace the code...
Require_once APPLICATION_PATH. '/models/class. phpmailer. php ';
// Send an email
Class Send_Mail {
Function send_mail ($ fromname, $ subject, $ content, $ user_mail)
{
$ Mail = new PHPMailer (); // instantiate
$ Mail-> IsSMTP (); // enable SMTP
$ Mail-> Host = "smtp.163.com"; // Sina mail of the SMTP server
$ Mail-> Port = 25; // mail sending Port
$ Mail-> SMTPAuth = true; // enable SMTP Authentication
$ Mail-> CharSet = "UTF-8"; // character set
$ Mail-> Encoding = "base64"; // Encoding method
$ Mail-> Username = "yzhjtx@163.com"; // your mailbox
$ Mail-> Password = "hjtx123456"; // your Password
$ Mail-> Subject = $ subject; // mail title
$ 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 the recipient address, nickname
$ Mail-> IsHTML (true); // html content is supported
$ Emailtype = "HTML"; // mail type, text: text; webpage: HTML
$ Mail-> Body = $ content; // mail content
If (! $ Mail-> Send ()){
Return false;
} Else {
Return true; // sent successfully
}
}
}
These are all custom prompts. the specific reason depends on the code. Trace the code...
Email code:
Require_once APPLICATION_PATH. '/models/class. phpmailer. php ';
// Send an email
Class Send_Mail {
Function send_mail ($ fromname, $ subject, $ content, $ user_mail)
{
$ Mail = new PHPMailer (); // instantiate
$ Mail-> IsSMTP (); // enable SMTP
$ Mail-> Host = "smtp.163.com"; // Sina mail of the SMTP server
$ Mail-> Port = 25; // mail sending Port
$ Mail-> SMTPAuth = true; // enable SMTP Authentication
$ Mail-> CharSet = "UTF-8"; // character set
$ Mail-> Encoding = "base64"; // Encoding method
$ Mail-> Username = "yzhjtx@163.com"; // your mailbox
$ Mail-> Password = "hjtx123456"; // your Password
$ Mail-> Subject = $ subject; // mail title
$ 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 the recipient address, nickname
$ Mail-> IsHTML (true); // html content is supported
$ Emailtype = "HTML"; // mail type, text: text; webpage: HTML
$ Mail-> Body = $ content; // mail content
If (! $ Mail-> Send ()){
Return false;
} Else {
Return true; // sent successfully
}
}
}
Invalid address
Invalid address
But the email has been sent, and my mailbox has received a new email.
Check whether there is any Invalid address prompt in class. phpmailer. php. if not, search for the entire project.
By looking at this information, you can see why. Basic debugging method!
The email prompt is incorrect.
If you can receive the email but the email server returns this prompt, you need to check the status received by 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-> conditions ){
Throw new phpmailerException ($ this-> Lang ('invalid _ address'). ':'. $ address );
}
Echo $ this-> Lang ('invalid _ address'). ':'. $ address;
Return false;
}
...