Php SMTP Error 10060 : FAILED TO CONNECT TO SERVER - php

I have php code to send email using SMTP connection; It was working perfectly 2 weeks ago. But suddenly stopped working. Don't know what the problem is.
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.
//start mailing function
require_once('PHPMailer_v5.1\class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
//MAIL config
$mail->SMTPAuth = true;
$mail->SMTPDebug = 1;
$mail->Host = "localhost"; // set as the SMTP server
$mail->Port = 25;
$mail->Username = "myemail#web.com"; // localhost email username
$mail->Password = "XXXX";
//End mail config
$mail->From = $sender_email;
$mail->FromName = $sender_user_name;
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->AddAddress($to,$to_name);
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {//to see if we return a message or a value bolean
echo "<p>Confirmation Mail delivery failed due to invalid email specified !</p>";
}

It was due to
$mail->Host = "localhost"; // set as the SMTP server
I changed it to
$mail->Host = "mail.web.com"; // set as the SMTP server
It works now!

Related

EOF caught while checking if connected phpmailer

require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'myhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myusername'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 1060; // TCP port to connect to
$mail->setFrom('test#gmail.com', 'test');
$mail->isHTML(true); // Set email format to HTML
$mail->addAddress('test#gmail.com'); // Add a recipient
for($i=0;$i<1;$i++){
$mail->Subject = "test bulk email ".$i;
$mail->Body = "this is email ".$i;
if(!$mail->Send())
{
$error_message = "Mailer Error: " . $mail->ErrorInfo;
}
}
echo $error_message;
When I run this code, I get this error:
Connection: opened 2018-03-05 09:24:25 SERVER -> CLIENT: 2018-03-05 09:24:25 SMTP NOTICE: EOF caught while checking if connected 2018-03-05 09:24:25 Connection: closed 2018-03-05 09:24:25 SMTP Error: Could not connect to SMTP host.
How do I fix this?
You're using an unusual port number for SMTP submission, so check you have the right one for your host. It would usually be 587 when using SMTPSecure = 'tls'.
You're setting a gmail from address while sending through another host; that will cause you to fail SPF checks and your messages will either be blocked or spam filtered.
If you want to send to a list, follow the mailing list example provided with PHPMailer - your code contains some mistakes that will probably result in duplicate messages.

Issues in connecting phpmailer with Office365

I need to send email using Office365 mail server from may webpage where user enters their email address.My configurations are as follows:
require("phpMailer/PHPMailerAutoload.php");
$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8';
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = trim($username);//username
$mail->Password = trim($password);//password
$mail->SMTPSecure = 'tls';
$fromName = 'Test';
$from = $myemail;
$mail->AddReplyTo($from, $fromName);
$mail->From = $from;
$mail->FromName = $fromName;
$mail->AddAddress($semail);//mail_id which i need to send mail
$mail->WordWrap = 80; // set word wrap
$mail->MsgHTML($_body);
$mail->IsHTML(true); // send as HTML
When I run the page,it gives following error message
Connection: opening
SMTP ERROR: Failed to connect to server:
php_network_getaddresses: getaddrinfo failed:
Name or service not known (0)
SMTP connect() failed.
**Fatal error**: Uncaught exception 'phpmailerException' with message
'SMTP connect() failed.
When I use gmail server configuration details(host:smtp.gmail.com) ,this is working fine.But my client mail server is with Office365.
I have used the ping command in command prompt for the mail server.
ping mail.mailservername.com <enter>
It gives IP address and another address for the above mail address.I have used the new mail address for the host variable. It works

PHPMailer's infamous SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed

I'm trying to get PHPMailer working using a Google Apps SMTP server. I've tried:
Uncommenting openssl in php.ini
Telneting Google's server on port 465 (success)
Telneting my webserver on port 465 (success)
Telnetting Google's server from my server (success)
Checking DNS SPF/MX records (and sanitizing to IPv4)
tls on port 587
webhost confirms they allow outbound SMTP traffic
google captcha's unlock trick
Reading everything I could find on StackOverflow (solutions covered the above)
Can someone provide a solution to the timed out connection?
Here's my code:
require_once ( 'class.phpmailer.php' ); // Add the path as appropriate
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server
$Mail->SMTPDebug = 1; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "ssl"; //Secure conection
$Mail->Port = 465; // set the SMTP port
$Mail->Username = 'account#googleappsaddress.com'; // SMTP account username
$Mail->Password = 'mypassword'; // SMTP account password
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Test Email Using Gmail';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = 'myemail#gmail.com';
$Mail->FromName = 'GMail Test';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->AddAddress( $to ); // To:
$Mail->isHTML( TRUE );
$Mail->Body = $body;
$Mail->AltBody = $MessageTEXT;
$Mail->Send();
$Mail->SmtpClose();
if(!$Mail->Send()) {
$error = 'Mail error: '.$Mail->ErrorInfo;
echo($error);
return false;
} else {
$error = 'Message sent!';
return true;
}
It turns out I was a victim of coincidence. When I ssh'ed to my server and telneted to Gmail, it was open - however, due to the openssl not being uncommented, I suspect that is why it initially failed.
However, while attempting to get it working, the host firewall blacklisted Gmail. They're currently looking into why, but the short answer is it is white-listed and working.

Connection error while sending email from host server

I have created a web application in php . I am using PHP Mailer 5.20 class. it work fine when I use XAMPP server on my local server but when we host it on a web-server and try to send a email the it return an error i show you the error below
SMTP -> ERROR: Failed to connect to server: Connection timed out (110)
SMTP Error: Could not connect to SMTP host.
I tried all configuration and check all but I receive the same error on the screen.
My PHP mailer class is below
<?php require("PHPMailer_5.2.0/class.phpmailer.php");
function send_email($tomail,$message,$subject)
{
//$dbObj = new Database();
//$dbObj->connect_db();
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.mail.yahoo.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
/////////////////////////////////( USER NAME AND PASSWORD )/////////////////////////////
$email = "xyxxxxx#yahoo.in";
$mail->Username = $email; // SMTP username
$mail->Password ="xxxxxx"; // SMTP password
$mail->From = $email;
$mail->AddAddress($tomail, $tomail);
// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody =$message;
$mail->Subject = $subject;
$mail->FromName ="xyz (Online Booking Info)";
if(!$mail->Send())
{ $rr= $mail->ErrorInfo;
exit;
}
}
?>
Can some body tell me where am I wrong or miss configuration?

Unable to connect to remote SMTP server

When i use this script to connect to SMTP server on same domain it works but when i use it for remote SMTP it gives error
$mail->IsSMTP(); // send via SMTP
$mail->Host = "xxx.xxx.x"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "xxxxt#xxxxx.com"; // SMTP username
$mail->Password = "xxxxx"; // SMTP password
$mail->Port = 26;
$mail->SMTPDebug = 1;
$mail->From = "email#domain.com";
$mail->FromName = "Name";
$mail->AddAddress("xxxx.oxxk#gmail.com");
//$mail->AddReplyTo("yourname#domain.com","Your Name");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the <b>HTML body</b>";
$mail->AltBody = "This is the text-only body";
if(!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
ERROR generated:
SMTP -> ERROR: Failed to connect to server: Connection refused (111)
SMTP Error: Could not connect to SMTP host. Message was not sent
Mailer Error: SMTP Error: Could not connect to SMTP host.
Can anyone plz point out what i have missed.
Thanks
1st are you running this script on your local computer like wamp or xammp server's .. if yes than you need to download a free smtp server you can try postcast server it works with windows... and then make some changes in php.ini file
http://www.postcast.com/html/download.asp ( download it from here )
Changes for php.ini file
SMTP = localhost
smtp_port = 25
sendmail_from = someid#somemail.com // this will the defualt address used to send mail you can even put your gmail id

Categories