PHPMailer could not connect to SMTP host
Asked Answered
P

4

9

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.

Photoengrave answered 26/5, 2011 at 10:45 Comment(7)
Well, the error message looks pretty clear. Are you sure smtp.your-domain.com exists? Who gave you that information, the web host?Ploughman
The error is exactly there: “Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?”Adellaadelle
telnet smtp.your-domain.com 587, is there a service responding?Xebec
I have tried with ping and it could not find host. but mail.<my-domain>.com returned some IP address, so it must be available. Now, what i need to change?Photoengrave
@Marcel Korpel: Where did you get that error message from? :)Quadric
@inquam: See revision #3Adellaadelle
@ both. sorry guys, I don't know how it has got revised. :( Now it is final update of question.Photoengrave
Q
7

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.

Quadric answered 26/5, 2011 at 11:24 Comment(4)
Can you ping the host from the computer that is running your php application? If you can then the server is atleast alive. Then try to telnet to the SMTP port you are trying to connect to and see what it replies.Quadric
I can ping with mail.mydomain.com, but smtp.mydomain.com is not found on ping. telnet with mail.mydomain.com replies.... Could not open connection to the host on port 23: connect failedPhotoengrave
try to telnet to mail.mydomain.com on port 587 (since that's the one you use in your php script). And change from smtp. to mail. in you php script.Quadric
change from smtp.mydomain.com to mail.mydomain.com as u suggested gives this error-> SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060) SMTP Error: Could not connect to SMTP host. There was a problem sending this mail!Photoengrave
J
4

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
Jones answered 28/6, 2014 at 20:11 Comment(2)
@JustLearninThisStuff, this solution worked for me, i pointed to the op address instead of URL and it worked.Ilana
This worked for me too, which is weird. The smtp host was working fine until this morning, then it stopped working for no apparent reason. Switching to the IP address fixed it.Odoacer
N
3

I had this problem a while ago, everything checked out just fine but the problem persisted. A reboot of httpd.service solved it.

Neuropath answered 30/6, 2014 at 11:16 Comment(2)
And who would have thought of that ... this fixed the issue in my case. Thank youOmor
How to do that?Solander
C
0

Had this issue after restart of computer where docker container with apache webserver was running.

Apache server hosted php code which stopped sending emails after computer restart.

Restarting apache docker container solved the issue.

Cooks answered 16/9, 2021 at 7:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.