can anyone help me figure out what the problem is here. I've done lots of searches and have done what I've found to no success.
here is my error, phpmailer is newest version
2015-08-08 13:15:03 Connection: opening to ssl://smtp.mysite.com:465, timeout=300, options=array ( ) 2015-08-08 13:15:04 SMTP ERROR: Failed to connect to server: Connection refused (111) 2015-08-08 13:15:04 SMTP connect() failed.
here is my code.
$m = new PHPMailer;
//Setup
$m->isSMTP();
$m->SMTPAuth = true;
//authentication
$m->Host = 'smtp.gmail.com';
$m->Username = 'info#example.com';
$m->Password = 'password';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->SMTPDebug = 3;
//from
$m->AddReplyTo($email, $name);
$m->SetFrom('info#example.com', $name);
//to
$m->addAddress('ari#example.com','guy johnson');
$m->addCC('joe#example.com','Joe johnson');
//message
$m->Subject = $subject;
$m->Body = $message;
if(!$m->Send()) {
echo"<script type=\"text/javascript\">".
"alert('A Error Occured, Please Try Again.');".
"</script>";
} else {
echo"<script type=\"text/javascript\">".
"alert('Message Sent. Please allow atleast 24-hours for a response');".
"window.location='http://example.com';".
"</script>";
}
thanks in advance!
Your error message shows smtp.example.com in the error but your code shows smtp.gmail.com. Have you tried port 25? The Google documentation suggests trying that with SSL.
Related
I've been using phpMailer to send emails until few days ago, and it stopped working surprisingly.
I'm using GMAIL SMTP server as a host.
Here's what the Exception and debugging message shows in console :
2017-12-19 05:39:02 Connection: opening to ssl://smtp.gmail.com:465, t=10, opt=array (
)
2017-12-19 05:39:02 SMTP ERROR: Failed to connect to server: (0)
2017-12-19 05:39:02 SMTP connect() failed.
And here's my mail functionality:
public static function mailTo($recipients)
{
$f3 = \Base::instance();
$edit = $f3->get('editTrue');
$user = AclHelper::getCurrentUser();
$template= new \Template;
if(isset($edit))
{
$mailBody = $template->render('leave/requestEdit.html');
}
else
{
$mailBody= $template->render('leave/emailTemp.html');
}
// When true, PHPMailer returns exceptions
$mail = new PHPMailer(true);
try {
$mail->isSMTP(); // Set mailer to use SMTP
$mail->isHTML(true);
$mail->addAddress($user['email']);
$mail->addAddress("malakar.rakesh1993#gmail.com");
// foreach($recipients as $recipient){
// $mail->addCC($recipient);
// }
$mail->SMTPDebug = 4;
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->Username = "malakar.rakesh1993#gmail.com";
$mail->Password = "abc123";
// $mail->Host = $f3->get('GBD.smtp.host'); // Specify main and backup SMTP servers
$mail->setFrom($user['email']);
$userFullName = trim(ucfirst($user['firstname'])) . " " . trim(ucfirst($user['lastname']));
$mail->FromName = $userFullName;
$mail->Body = $f3->get('message');
$mail->Body .="<br>". $mailBody;
if(isset($edit))
{
$mail->AltBody = '';
}
else
{
$mail->AltBody = 'Hello.. Not working';
}
$mail->Subject = 'Updates on leave date applied';
$mailStatus = (boolean)$mail->send();
if ($mailStatus === true)
{
return $mail;
}
}
catch (phpmailerException $e)
{
$response = array(
'status'=>'error',
'message'=>'Got some error while sending emails',
'exceptions'=>$e->getMessage()
);
return $response;
}
catch (Exception $e) {
$response = array(
'status'=>'error',
'message'=>'Got some error while sending emails',
'exceptions'=>$e->getMessage()
);
return $response;
}
}
I also tried using tls as encryption protocol and 587 port, but gives 500 internal server error.
The same code is running in development version in server, but unfortunately not in my localhost.
I was suggested of out-dated CA certificate in my system, and I tried renewing the up-to-date CA certificate following the link Trobuleshooting, but it's not working either.
Stupid maybe but I tried pinging to smtp.gmail.com [without ssl and port] in my command prompt and I'm receiving feedback.
Could it be that Google limits email sending? But I can still access my account.
I have followed almost every articles and solutions available in the Internet.
Please help me through this...this is driving me crazy.
Any help is very much appreciated. Thanks...
I am trying to send an email using Mailer but getting below error
Connection: opening 2017-05-25 08:22:07 SMTP ERROR: Failed to connect
to server: (0) SMTP connect() failed. Mailer Error: SMTP connect()
failed.
php_openssl extension & IMAP both are enabled. I tried to find it on google but still no luck.
Code:
function sendMail($subject='',$to='',$emailcontent='',$attach='')
{
global $_mailmsg;
//echo $emailcontent;exit;
$mail = new PHPMailer;
$mail->SMTPDebug = 4;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = '465';
$mail->SMTPAuth = true;
$mail->Username = 'xx#gmail.com';
$mail->Password = 'xxxx';
$mail->SMTPSecure = 'ssl';
$mail->From = 'xx#gmail.com';
$mail->FromName = 'Test';
$mail->addAddress($to); // Add a recipient
if(!empty($cc)){ $mail->addCC($cc); }
if(!empty($bcc)){ $mail->addBCC($bcc); }
$mail->WordWrap = 50;
if($attach != ''){
$mail->addAttachment($attach);
}
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = 'Test';
try
{
if($mail->send()) {
return 1;
exit;
}
else
{
echo 'Mailer Error: ' . $mail->ErrorInfo;
return 0;
}
}
catch(Exception $e)
{
return 0;
}
}
This looks like your server is not permitted to connect to remote SMTP servers, something very common at big ISPs like GoDaddy. If you do the steps described in the troubleshooting guide you can figure out what's blocking you. The fact that there is no link to the guide in your error message tells me that you're using a very old version of PHPMailer, so get the latest.
PHPMailer has nothing to do with IMAP; that's for inbound mail only.
As you are using Gmail, just turn on "Allow less secure apps":
https://myaccount.google.com/u/0/lesssecureapps
And also you'll probably need to allow access to your Google account without unlock captcha:
https://accounts.google.com/DisplayUnlockCaptcha
I search google and this site and can't fix this phpMailer error and that's why I need you help.
I am sending email using following phpMailer code but all time it's showing me error message :
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
PhpMailer Code
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = gethostbyname("smtp.gmail.com");
$mail->SMTPAuth = true;
$mail->Username = 'hello#gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->isHTML(true);
$mail->Priority = 1;
$to = 'to#gmail.com';
$mail->setFrom('support#site.com', 'Sitename');
// Send Email tto user ####################################
$mail->addAddress('some#gmail.com', 'Shibbir Ahmed');
// send email to admin #####################################
$mail->addReplyTo('some#gmail.com', 'Information');
$mail->Subject = 'Test Subject';
$get_templae = mysqli_query($conn, "SELECT * FROM email_template WHERE t_id = '8' ");
$get_restult = mysqli_fetch_array($get_templae);
$template = $get_restult['t_content'];
$mail->Body = $template;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Can you please tell what I am doing wrong in this code ?
I am getting this error :
2016-04-21 15:19:51 SMTP ERROR: Failed to connect to server: Connection refused (111) 2016-04-21 15:19:51 SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Update :
Current Error from my server :
2016-04-21 18:06:01 SMTP ERROR: Failed to connect to server: Connection refused (111) 2016-04-21 18:06:01 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting bool(false)
Try to lower your gmail security, for the SMTP!
Link: https://www.google.com/settings/security/lesssecureapps
And add de debuginfo property to see more what is wrong.
$mail->SMTPDebug = 1;
you can change the value to 1 2 3 or 4 to ingress the filtering form debuginfo.
Hope this helps you out ;)
The best ways to debug PHPMailer errors is to uncomment
$mail->SMTPDebug = 3;
It will give you a detailed log of the events happening. From authentication all the way to where the request is successful or fails
Step1: Go to Gmail setting and enable IMAP.
Step2: Clear your browser cache and check it.
If issue still persists lower your Gmail security by using "settings" tab.
Gmail Security alert will be like this
<?php
require '/etc/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "my#gmail.com";
$mail->Password = "password";
$mail->SetFrom("from#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("to#gmail.com");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
This is my mail functionality code & it gives me the error
SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No address associated with hostname
I don't have extension=php_openssl.dll in my php.ini file but still I've included this and the same issue
To avoid the problem of dynamic IP (every time i ping smtp.gmail.com I see a slight difference in the last 3digit chunk), you just have to use php built-in gethostbyname() to read the IP in real-time.
$smtp_host_ip = gethostbyname('smtp.gmail.com');
Then use that as host.
Hope it helps.
I am using the following code to sent mail for a contact form. The mail works perfectly when using a windows server setup with xampp, but fails in Linux server RHEL 5.
I am getting "SMTP Error: Could not connect to SMTP host". I tried telnet the host from terminal. It is getting connected
public function smtpmailer($to,$cc, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->IsHTML();
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'XXX#gmail.com';
$mail->Password = 'XXXXXXXX';
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
$mail->AddCC($cc);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
While Debugging is set to 1 I am getting the following error
SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
SMTP Error: Could not connect to SMTP host.
Seems as if name resolving is not working. Check /etc/resolv.conf, it should contain a line like this:
nameserver 8.8.8.8
Replace 8.8.8.8 by the IP of your desired nameserver.