SMTP error:could not connect to SMTP host. How to Resolve

Source: Internet
Author: User
Tags gmail password
SMTP error:could not connect to SMTP host.
I use the Web page runtime Normal, can send, with the command to run PHP file times wrong, the main code is checked correctly, as follows
function SendMail ($setEmail, $setName, $body, $subject) {
Require_once ("phpmail/phpmailer.php");
$mail = new Phpmailer (true); The true param means it would throw exceptions on errors and which we need to catch
$mail->issmtp (); Telling the class to use SMTP
try {
$mail->smtpauth = true; Enable SMTP Authentication
$mail->smtpsecure = Sbt_ssl; Sets the prefix to the Servier
$mail->host = sbt_smtp_host; Sets GMAIL as the SMTP server
$mail->port = Sbt_smtp_port; Set the SMTP port for the GMAIL server
$mail->username = Sbt_smtp_user; GMAIL username
$mail->password = Sbt_smtp_pass; GMAIL Password
$mail->addreplyto (Sbt_mail_from, sbt_mail_from_name);
$mail->addaddress ($setEmail, $setName);
$mail->setfrom (Sbt_smtp_user,sbt_smtp_user); Sender Name
$mail->subject = $subject;
$mail->msghtml ($body);
if (! $mail->send ()) {//(no error on this side)
echo "Message could not being sent.

";
echo "Mailer Error:". $mail->errorinfo;
Exit ();
}
} catch (Phpmailerexception $e) {
echo $e->errormessage (); Pretty error messages from Phpmailer (this is the output error)
} catch (Exception $e) {
echo $e->getmessage (); Boring error messages from anything else!
}
}


Ask what the reason is, the purpose is to be able to execute the PHP file with a Linux scheduled task


------Solution--------------------
What about the error code?
------Solution--------------------
PHP--ini to see if the INI used is consistent with PHP running as an Apache module.
------Solution--------------------
No, $mail->issmtp (); This indicates that you have set up SMTP send.
Your main problem now is to find out why the socket cannot connect to the SMTP server.
Firewalls are also possible.
------Solution--------------------
Wamp environment, should be shared with an INI file. Want to be sure again, PHP Web Output phpinfo (), see the use of INI file, whether and this consistent.
Command: Telnet smtp.gmail.com 465, OK to connect successfully?
------Solution--------------------
Check the firewall, and then check the code that sends the picture attachment.
------Solution--------------------
Telnet is no good, it must be your firewall has forbidden access
  • 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.