Unable to connect to remote SMTP server - php

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

Related

smtp connect failed in smtp mail

i have a issue sending mail using smtp mail class when i use my send email code using smtp in my local system at that time is working prefect but when i try that code in live server i got every time smtp connect failed error
i use this code for send mail using smtp mailer class
require 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'myemail#gmail.com';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'tls';
$mail->From = 'myemail#gmail.com';
$mail->FromName = 'Mailer';
$mail->addAddress('myemail#gmail.com', 'Joe User');
$mail->addAddress('myemail#gmail.com');
$mail->addReplyTo('myemail#gmail.com', 'Information');
$mail->addCC('myemail#gmail.com');
$mail->addBCC('myemail#gmail.com');
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';}
that is my code it working in local but not working in live server
i did all setting in my php.ini file like smtp and user password
but still not working so please give me proper solution or code that working in live server
this is error
2016-07-07 17:23:09 SMTP ERROR: Failed to connect to server: Network is unreachable (101) 2016-07-07 17:23:09 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
when you are in local at that time smtp.gmail.com its working but in live you need your server host address like mail.servername.com
You must first of all activate gmail accepting non secure apps
Use real email for sender and receiver 'Make sure of the password'
change
$mail->SMTPSecure = 'tls';
to
$mail->SMTPSecure = 'ssl';
//tls for localhost and ssl for host server 'onligne'
add port
$mail->Port = 465 ; // or 587
may work for you :)

SMTP -> ERROR: AUTH not accepted from server: 530 5.7.0 Must issue a STARTTLS command first

<?php
require("class.phpmailer.php");
require("class.smtp.php");
require("class.pop3.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.mail.yahoo.com"; // specify main and backup server
$mail->SMTPSecure = "SSL";
$mail->SMTPKeepAlive = true;
$mail->Port = "587";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPDebug = 1;
$mail->Username = "abc#yahoo.com"; // SMTP username
$mail->Password = "xyz"; // SMTP password
$mail->From = "abc#yahoo.com";
$mail->FromName = "Prashant kumar";
$mail->AddAddress("pqr#gmail.com", "Yogesh"); // name is optional
$mail->AddReplyTo("mno#gmail.com", "Information");
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
Trying from last 2 days, getting the error as
SMTP -> ERROR: AUTH not accepted from server: 530 5.7.0 Must issue a STARTTLS command first
SMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.
Already seen all possible questions in stackoverflow and other websites.
Already changed SMTPSecure and Port to all possible values.
Tried gmail server and outlook server also.
Changed SMTPsecure to STARTTLS and TLS also with respective ports.
Removed SMTPAuth line also.
Tried every possible soultions i found through web.
Is this because i am trying to run this on my localhost?
(i am using XAMPP in windows 8, 64 bit)
Try using $mail->Port = 465; instead of 587 and check the difference in the below link.

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?

Sending an email using PHPMailer and GMAIL SMTP

I have read every example out in the web and I still cant seem to connect to the GMAIL SMTP. Here is the code that I am running:
include("phpMailer/class.phpmailer.php"); // path to the PHPMailer class
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myUsername"; // SMTP username
$mail->Password = "myPassword"; // SMTP password
$mail->SMTPDebug = 1;
$webmaster_email = "webMasterEmail#gmail.com"; //Reply to this email ID
$email="someone#gmail.com"; // Recipients email ID
$name="SomeonesName"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Me";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
I tried setting the port in here and I also have the current set up with the following in the class.smtp.php file:
$host = "ssl://smtp.gmail.com";
$port = 465;
I keep getting the same error and I have made sure that ssl is enabled. The error I get is:
SMTP -> ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it.(10061)
As I mentioned above I had already enabled ssl by getting rid of the ; on the line with php_openssl.dll and restarting Apache. I did some more reading and I found out that some people also had "[PHP_OPENSSL]" before the enabling command. I added it and restarted Apache and everything is working! Thanks for all the comments
In php.ini:
[PHP_OPENSSL]
extension=php_openssl.dll

PHP mailer error

I tried to use php mailer but errors as follows.
SMTP -> FROM SERVER:
SMTP -> FROM SERVER:
SMTP -> ERROR: EHLO not accepted from server:
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedSMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.
and my code
<?php
require("class.phpmailer.php")
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPDebug = 2;
$mail->Username = "admin#xxxxxxxxxxxx.in";
$mail->Password = "xxxxxxxx";
$mail->From = "admin#xxxxxxxxxxxx.in";
$mail->FromName = "Mailer";
$mail->AddAddress("xxxx#yahoo.co.in", "mine");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Here is the subject"
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send()) {
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
I was getting this due to wrong port for SSL.
SSL = 465
TLS = 587
See:
http://mail.google.com/support/bin/answer.py?hl=en&answer=13287
Some servers (especially shared hosting) will block you from using SSL with SMTP, I had the same problem once.
Either change host if you can, try using the default PHP mail() function or send through another mail server that does not require SSL e.g. port 25 not 465.
Something like AuthSMTP would be your best bet for an alternate mail server.
I had the same problems, it seems that we have
to set the SMPTSecure value.
First I changed the port from 465 to 587 and added:
$mail->SMTPSecure = "tls";
and it worked :)
If you are working in your localhost just go to the PHP Extention and enable or check the php_openssl
it will be able to access the SSL ports.
try this code
require 'PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
//$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
//$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "admin#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "admin123";
$mail->setFrom('admin3#gmail.com', 'development'); //add sender email address.
$mail->addAddress('admins#gmail.com', "development"); //Set who the message is to be sent to.
//Set the subject line
$mail->Subject = $response->subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->Body = 'Name: '.$data['name'].'<br />Location: '.$data['location'].'<br />Email: '.$data['email'].'<br />Phone:'.$data['phone'].'<br />ailment: '.$data['ailment'].'<br />symptoms: '.$data['symptoms'];
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.gif');
//$mail->SMTPAuth = true;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Had the same issue, Change port No in opencart mail setting to 587 and works fine
May be because of fire wall?
If you can't sign in to Google Talk,
or you're receiving an error that
says, Could not authenticate to
server, check if you have personal
firewall software installed, or if
your computer is behind a proxy server
that requires a username and password.
http://www.google.com/support/talk/bin/answer.py?hl=en&answer=30998
I use the same script for several clients and only run into this problem when deploying to Amazon EC2 cloud providers (such as Openshift).
These are tried and tested settings in phpmailer:
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587;
'but' Google blocks these services as an 'anti-spam' / political maneuver, and this has caught me out because it works locally and on most hosting providers, there is nothing much you can do when they don't accept outbound messages from your hosts DNS / IP. Accept it and move on by looking for another smtp server to route messages through.
not sure but try $mail->Host = "smtp.gmail.com" =>$mail->Host = "smtp.google.com"

Categories