PHPMailer prompts CalledMail () withoutbeingconnected error and uses PHPMailer to send an email. according to the example, I typed the following code:
Require ("class. phpmailer. php "); // the downloaded file must be placed in the directory where the file is located $ mail = new PHPMailer (); // create an email sending class // $ address =$ _ POST ['address']; $ mail-> IsSMTP (); // use SMTP to send $ mail-> Host = "mail.qq.com"; // your enterprise Post Office domain name $ mail-> Port = '25 '; // $ mail-> SMTPAuth = true; // enable the SMTP authentication function $ mail-> Username = "497045318@qq.com"; // Post Office Username (enter the complete email address) $ mail-> Password = "******"; // Post Office Password $ mail-> From = "497045318@qq.com"; // mail sender email address $ mail-> FromName = "Frank Tung"; $ mail-> AddAddress ("tongzhenhang@qq.com"); // recipient address, which can be replaced with any email address you want to receive, the format is AddAddress ("recipient email", "recipient name") // $ mail-> AddReplyTo ("",""); // $ mail-> AddAttachment ("/var/tmp/file.tar.gz"); // add attachments // $ mail-> IsHTML (true ); // set email format to HTML // whether to use the HTML format $ mail-> Subject = "PHPMailer test mail"; // mail Title $ mail-> Body = "Hello, this is the test email "; // the email content $ mail-> AltBody =" This is the body in plain text for non-H TML mail clients "; // additional information, which can be omitted if (! $ Mail-> Send () {echo "failed to Send the email."; Echo" error cause: ". $ mail-> ErrorInfo; exit;} echo" email sent successfully ";
Result
An error occurred while sending the email.
Error cause: The following From address failed: 497045318@qq.com: Called Mail () without being connected
I tried
/**
* Method to send mail: ("mail", "sendmail", or "smtp ").
* @ Var string
*/
Var $ Mailer = 'mail ';
Change
Var $ Mailer = 'smtp ';
This error persists.
I will search for smtp of QQ again. The webpage is as follows:
Http://kf.qq.com/faq/120322fu63YV130422nqIrqu.html
Add $ mail-> Host = "mail.qq.com ";
Change
$ Mail-> Host = "smtp.qq.com ";
$ Mail-> Port = '000000 ';
Or error.
Change
$ Mail-> Port = '000000 ';
Error message:
An error occurred while sending the email.
Error cause: The following From address failed: 497045318@qq.com: MAIL not accepted from server, 530, Must issue a STARTTLS command first.
SMTP server error: Must issue a STARTTLS command first.
SMTP server error: Must issue a STARTTLS command first.
I have a tutorial video on Youtube.
InMotion Hosting-How to use PHPMailer
Https://www.youtube.com/watch? V = JltHLzkghmY
My code is basically the same as him. The only difference is that I am on the localhost of my local computer, rather than on the server (I don't have a personal server yet). I think it is related to this factor.
I would like to ask you why. Thank you! If you have any good methods or code, you can use php to send an email. please also ask!
Reply to discussion (solution)
The cause is found.
When I was testing the function, I had to troubleshoot a row of errors.
// $ Mail-> SMTPAuth = true; // enable SMTP Authentication
In troubleshooting, I commented out the above line and finally forgot to remove the comment.
So this line is indispensable.