Phpmailer how to send mail to SMTP error:could does connect to SMTP host workaround

Source: Internet
Author: User
Tags how to send mail
Before doing a project to do a phpmailer to send mail with the function of "CI framework combined with phpmailer send mail", yesterday step on the line (just start with Sina cloud, too expensive, replaced by Ali), the test, send an email unexpectedly error ....

I wipe, not on-line time good, the second success, just started I thought is the SMTP address problem (I use 163 mailbox), later changed to QQ mailbox, found or no use, no way, had to ask degrees Niang, later looked at the answer on Baidu to understand in addition to Google's SMTP server received the request " SMTP "will accept that other servers are like the 163,QQ I'm using and must receive an uppercase" SMTP "Request ... emmmmm .....

Then I am in class.phpmailer.php , will


1 public Function Issmtp () {2     $this->mailer = ' smtp '; 3   }4 5//changed to 6 Public function issmtp () {7     $this->mai ler = ' SMTP '; 8   }

Then you will:


1 switch ($this->mailer) {  2 case         ' SendMail ':  3           return $this->sendmailsend ($header, $body);  4 Case         ' SMTP ':  5           return $this->smtpsend ($header, $body);  6         Default:  7           return $this->mailsend ($header, $body);  8       }  9  11//Change to switch ($this->mailer) {case         ' sendmail ':           return $this Sendmailsend ($header, $body); Case         ' SMTP ':           return $this->smtpsend ($header, $body);         default:18           return $this MailSend ($header, $body); +       }

I thought that would do it, restart Apache, test again, the results of the first error is resolved, and an error occurred:

Could Not instantiate mail function

?????

Do not know whether you have appeared, my bad luck, had to turn to the degree Niang, finally found the reason: some virtual host, or server, in order to be safe to shield the "fsockopen () function" cause unable to send the message.

Here's the solution:

First, remove the following two semicolons from the php.ini

; Extension=php_sockets.dll

; Extension=php_openssl.dll

I had already removed it with Phpmailer, just a hint.

Then replace the Fsockopen function

Replace the Fsockopen function in the class.smtp.php file with the Pfsockopen function:


1 $this->smtp_conn = @fsockopen ($host,    //The host of the server  2                                                    $port,    //The port to use  3                                  $errno,   //error number if any  4                                  $errstr,  //error message if any  5                                  $tval);   Give up after? secs  6   7   8//fsockopen Change  to: 9 $this->smtp_conn = @pfsockopen ($host,    //The host of the server                                  $port,//The port to use one                                  $errno,   //error number if any                                  $errstr,  //error message If any                                  $tval);   Give up after? secs

So set up, I have been able to successfully send mail, if the same problem, you can refer to the above example to try.

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.