Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer could not connect to SMTP host

getting following error:

SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0) SMTP Error: Could not connect to SMTP host. There was a problem sending this mail!

This is my config file setting as I have followed this PHPMailer tutorial

// Configuration settings for My Site

// Email Settings
$site['from_name'] = 'Manish Dekavadiya'; // from email name
$site['from_email'] = 'manish@<my-domain>.com'; // from email address

// Just in case we need to relay to a different server,
// provide an option to use external mail server.
$site['smtp_mode'] = 'enabled'; // enabled or disabled
$site['smtp_host'] = "smtp.<my-domain>.com";
$site['smtp_port'] = 587;
$site['smtp_username'] = "manish@<my-domain>.com";
$site['smtp_password']="<password>";

and used mailer class and an extended class as mentioned in tutorial as following:

/*****sendmail.php****/

// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');

// Grab the FreakMailer class
//echo $_SERVER['DOCUMENT_ROOT'];
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');

// instantiate the class
$mailer = new FreakMailer();

// Set the subject
$mailer->Subject = 'This is a test';
 $mailer->SMTPDebug = 1;
// Body
$mailer->Body = 'This is a test of my mail system!';

// Add an address to send to.
$mailer->AddAddress('[email protected]', 'Manish Dekavadiya');

if(!$mailer->Send())
{
    echo 'There was a problem sending this mail!';
}
else
{
    echo 'Mail sent!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();

also getting another error when I tried an example given in phpmailer docs @ examples/test_smtp_gmail_basic.php

SMTP -> ERROR: Failed to connect toserver: php_network_getaddresses: getaddrinfo failed: No such host is known. (0) SMTP Error: Could not connect to SMTP host. There was a problem sending this mail!

so there must be setting or configuration error. there can't be code error.

like image 229
maniclorn Avatar asked May 26 '11 10:05

maniclorn


People also ask

Can't connect to SMTP host SMTP?

Error: SMTP error: could not connect to SMTP host However, there are some common aspects that you may need to validate before proceeding further. Security Restrictions. Temporary connection issues. Invalid client-side settings.

How do I fix SMTP failed to connect to server?

Modify the server's firewall rules to permit outbound connections on ports such as 465. Change the server's SMTP restrictions. Then, add the specified website user to the list of users who are authorized to initiate outbound SMTP connections. Edit PHPMailer's configuration settings, such as host and port.

Can't connect to SMTP server?

This could be due to a temporary issue with their network or mail server or due to a configuration within your middleware (firewall, antivirus, etc.) blocking the connectivity.

Does PHPMailer use SMTP?

PHPMailer can use a non-local mail server (SMTP) if you have authentication. Further advantages include: It can print various kinds of error messages in more than 40 languages when it fails to send an email. It has integrated SMTP protocol support and authentication over SSL and TLS.


2 Answers

Is SMTP set up on ? And if so is it configured to listen to smtp..com on port 587? If the server is not set up by yourself it's not uncommon that they listen to mail..com instead. Also, try to connect to port 25 to see if it might be configured to listen to the default smtp port.

The error messages is in any case very clear. The host is not responding to your connection attempt. The reason could be missconfigurations in both the server and in PHP, firewall issues, routing issues, DNS issues etc.

like image 69
inquam Avatar answered Oct 06 '22 23:10

inquam


Hopefully this helps someone else out there because I was fighting this same error. First I was getting. I was getting an error that said it couldn't connect(). Then I turned on the debugging and got the error you mentioned. The solution that worked for me was to change the smtp..com to the ip address.

$mail->Host = 'smtp.whateverDomain.com';

to

$mail->Host = 'theIPaddress';

debugging

$mail->SMTPDebug  = 1; // enables SMTP debug information (for testing)
                           // 1 = errors and messages
                           // 2 = messages only
like image 36
JustLearninThisStuff Avatar answered Oct 07 '22 01:10

JustLearninThisStuff