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