PHPMailer cannot send email

My project contains an email sending function which is PHPMailer

. It works well for sending email from my local server, but today it stops sending email and now it shows this error message

SMTP Error: Could not connect to SMTP host.

      

I added this code $mail->SMTPDebug = 1;

to view debug errors and now it shows me this message:

SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: The requested name is valid, but no data of the requested type was found.  (0) SMTP Error: Could not connect to SMTP host

      

I already have enabled extension=php_openssl.dll

a php.ini

.

This is my code:

$mail = new PHPMailer();
$mail->SMTPSecure = 'ssl';
$mail->IsSMTP();
$mail->Username = "myemail@gmail.com"; // your GMail user name
$mail->Password = "password"; 
$mail->AddAddress($email); // recipients email 
$mail->FromName = "username"; // readable name
$mail->IsHTML(true);
$mail->Subject = "title";
$mail->Body    = " Message"; 
$mail->SMTPDebug = 1; 
$mail->Host = "ssl://smtp.gmail.com"; // GMail
$mail->Port = 465;
$mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->From = $mail->Username;
if($mail->Send()){
} else {
}

      

thank

0


source to share


2 answers


This is usually reported as a PHPMailer issue (and there are many duplicates of this question), but it almost always depends on a local DNS failure, firewall blocking, or other network issues on your local network.

Make sure you are using the latest PHPMailer first .

Do not use SSL on port 465, it has been deprecated since 1998 and is only used by Microsoft products that did not receive the note; use TLS on port 587 instead:

$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;

      

or more succinctly:

$mail->Host = 'tls://smtp.gmail.com:587';

      

You can connect to this by running some commands on your server (you need packages dnsutils

and telnet

). First DNS check works:

dig +short smtp.gmail.com

      

You will get something like this if your DNS is working:



gmail-smtp-msa.l.google.com.
173.194.67.108
173.194.67.109

      

Then try installing telnet on the host on the correct port:

telnet smtp.gmail.com 587

      

This should give you something like this:

Trying 173.194.67.109...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP ex2sm16805587wjd.30 - gsmtp

      

(Enter quit

to get out of this).

If any of these don't work, PHPMailer won't work . So fix your network and then try again. If you are not in control of your own firewall or DNS, you may have to raise a support ticket with your ISP to fix this. If they are not fixed, you will need to replace your ISP.

Back in PHPMailer, you can get lower level feedback on the connection by setting:

$mail->SMTPDebug = 4;

      

+2


source


A simple google search showed this forum - http://forums.devshed.com/php-development-5/unable-to-find-the-socket-transport-ssl-667689.html



0


source







All Articles