php - Phpmailer using smtp with Gmail not working - connection timing out -
i've looked following links:
phpmailer send gmail smtp timeout
send email using gmail smtp server through php mailer
http://uly.me/phpmailer-and-gmail-smtp/
...and tried implement myself combination of however...most of time sends message...
message not sent.
mailer error: smtp connect() failed.
however there 1 time sent when experimented between "tls" , "ssl"...
smtp error: failed connect server: connection timed out (110) smtp connect() failed. message not sent.
mailer error: smtp connect() failed.
my code attached...did somehow miss something? asked web hosting service if they're blocking , gave them template of code - said server allows connections gmail's smtp.
require_once("class.phpmailer.php"); $mail = new phpmailer(); $mail -> issmtp(); $mail -> smtpdebug = 2; $mail -> smtpauth = 'true'; $mail -> smtpsecure = 'tls'; $mail -> smtpkeepalive = true; $mail -> host = 'smtp.gmail.com'; $mail -> port = 587; $mail -> ishtml(true); $mail -> username = "myemail@gmail.com"; $mail -> password = "mypassword"; $mail -> singleto = true; $to = xxx; $from = xxx; $fromname = xxx; $subject = xxx; $message = xxx $headers = "from: $from\n"; $headers .= "mime-version: 1.0\n"; $headers .= "content-type: text/html; charset=iso-8859-1\n"; $mail -> = $from; $mail -> fromname = $fromname; $mail -> addaddress($to); $mail -> subject = $subject; $mail -> body = $message; if(!$mail -> send()){ echo "message not sent. <p>"; echo "mailer error: " . $mail-> errorinfo; exit; }
i dug it. use fsocketopen, native php, test connection , eliminate of potential problems. write simple php page this:
$host = "smtp.gmail.com"; $port = "587"; $checkconn = fsockopen($host, $port, $errno, $errstr, 5); if(!$checkconn){ echo "($errno) $errstr"; } else { echo 'ok'; }
you should "ok". if not know have connection problem has nothing phpmailer. if that's case it's hosting company. if not it's simple difference between local host , hosting company different versions of php.
i suspect though script won't make connection
Comments
Post a Comment