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 :)
Related
how do i make gmail accept the phpmailer from localhost and not prevent signing in?
how do i fix this error message
Message could not be sent.Mailer Error: SMTP connect() failed.
<?php
require 'PHPMailer-master\PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'my#gmail.com'; // SMTP username
$mail->Password = 'valid'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('my#gmail.com', 'me');
// Add a recipient
$mail->addAddress('their#gmail.com'); // Name is optional
$mail->addReplyTo('my#gmail.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$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.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
It seems a connection to Google SMTP on port 587 is not being made. Are you in a network where port 587 is blocked. You can simply check if a connection can be made by using this telnet command:
telnet smtp.gmail.com 587
You will get a response as shown in snapshot
The Telnet client in Windows is disabled by default, and needs to be enabled via Windows' Programs and Features:
Control Panel --> Programs --> Turn Windows features on or off, in the dialog that pops up check-mark "Telnet Client".
Or you can download Putty
I'm trying to send a mail with PHPMailer (SMTP).
btw: the mail server is hosted by switchplus.ch...
But if i try to send a mail, I get the following error: "SMTP Error: Could not connect to SMTP host.
"
PHP code to send the mail:
<?php
require './mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.lordsofmahlstrom.li'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'support#lordsofmahlstrom.li'; // SMTP username
$mail->Password = 'secredPassword'; // SMTP password
$mail->SMTPSecure = 'tsl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('support#lordsofmahlstrom.li', 'Support');
$mail->addAddress('test#test.com', 'Tester'); // Add a recipient
$mail->addReplyTo('support#lordsofmahlstrom.li', 'Support');
$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.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
Does anyone know, what i did wrong?
it's $mail->SMTPSecure = 'tls';
not tsl
Also, if you want encryption, you have to connect to the host "smtp.mail-ch.ch" (Except of course you have you're own certificate.)
I just tried it and worked.
<?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.
I'm getting error SMTP connect() failed phpmailer with localhost:
2015-09-10 09:34:48 Connection: opening to ssl://smtp.gmail.com:587,
timeout=300, options=array ( ) 2015-09-10 09:34:48 SMTP ERROR: Failed
to connect to server: (0) 2015-09-10 09:34:48 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
Is it phpmailer cannot run at localhost?
If I want really run at localhost how can I change the code?
I tried using mailto function is work for me but I want change whole thing.
can give any suggestion. I really want to learn it.
This is the code from github:
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mygmail#gmail.com'; // SMTP username
$mail->Password = 'mygmailpassword'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//$mail->Host = 'tls://smtp.gmail.com:587';
$mail->From = 'ikramlim#gmail.com';
$mail->FromName = 'Mailer';
$mail->addAddress('ikramlim#gmail.com', 'Joe User'); // Add a recipient
$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.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
PHPMailer is normally working on all systems.
I think you have an old openssl extension or your extension is not enabled. Check that with a phpinfo() if there is openssl enabled.
If not then enable it in your php.ini.
And the other way is that it seems that Google has some problems. When i try to send an Email at the moment i have connection problems with Thunderbird, too. I have to try it some times to connect to gmail.
My suggestion is that please try using 'tls' with port 587 instead of 'ssl' with port 587.
Also check whether you are including class.phpmailer.php(ie: require 'class.phpmailer.php';) , If you are doing please comment it and give a try.
Connection: opening to smtp.mandrillapp.com:587, timeout=300, options=array ()
SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed.
Message could not be sent.Mailer Error: SMTP connect() failed.
I used mandrillAPI to send email. It works on my localhost. I can send mails from my localhost. But when I used this on the test server it is not connecting to the mandrill server. It shows the above error. I checked the port and it is open. I can use gmail smtp from my server. It works fine. But I need to use mandrillAPI. I also added DKIM and SPF record on domain. But still not connecting to the smtp.mandrillapi.com
here is the code I used.
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com'; // Specify main and backup server
$mail->Port = 587; // Set the SMTP port
$mail->SMTPDebug = 4;
$mail->Debugoutput='html';
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'example#gmail.com'; // SMTP username
$mail->Password = 'apikey'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'example#gmail.com';
$mail->FromName = 'example';
$mail->AddAddress('example#gmail.com', 'Nidheesh'); // Add a recipient
// Name is optional
$mail->addReplyTo('example#gmail.com');
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>';
$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;
exit;
}
echo 'Message has been sent';
?>
`