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.
Related
I've installed PHPMailer onto Windows Server 2012 R2 (using IIS) and I'm trying to use it to send an email, here is my code:
<?php
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mailer->Host = 'tls://smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myemailaddress#gmail.com'; // SMTP username
$mail->Password = 'MyPassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('myemailaddress#gmail.com', 'Martin');
$mail->addAddress('anotheraddress#emaildomain.co.uk', 'Hello'); // Add a recipient
//$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('anotheraddress#midlandairexpress.co.uk', 'Hello');
//$mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$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';
}
?>
As you can see I've enabled debug output andwhen I try to run this I get:
2017-05-07 20:36:28 Connection: opening to localhost:587, timeout=300, options=array ( ) 2017-05-07 20:36:30 Connection failed. Error #2: stream_socket_client(): unable to connect to localhost:587 (No connection could be made because the target machine actively refused it. ) [C:\inetpub\wwwroot\email\PHPMailer\class.smtp.php line 292] 2017-05-07 20:36:30 SMTP ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it. (10061) 2017-05-07 20:36:30 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
I've installed PHP screenshot of info
I've tried:
1. Looking through the GitHub documentation
2. Specifying the protocol before the name of the SMTP server (line 10)
3. Checking the SMTP info against Google's Support page
4. Checking the credentials of my email address (send from)
The PHPMailer folder is located within a folder on the server called email
(Path to PHPMailerAutoload.php)
C:\inetpub\wwwroot\email\PHPMailer\PHPMailerAutoLoad.php
I'm fairly new to PHP but I have a basic understanding of how it works.
Does anyone have any suggestions?
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 :)
hi my phpmailer is producing the following result when i execute my mailtest.php
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
i have gone through many questions about phpmailer in this forum but none has benefit me.
my mailtest.php
<?php
require ("/phpmailer/PHPMailerAutoload.php");
require ("/phpmailer/class.phpmailer.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 = 'thethih#gmail.com'; // SMTP username
$mail->Password = 'password.'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('from#example.com', 'Mailer');
$mail->addAddress('thethih#gmail.com', 'Joe User'); // Add a recipient
$mail->addAddress('thethih#yahoo.com'); // Name is optional
$mail->addReplyTo('info#example.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';
}
?>
any help will be appreciated .. and it is in localhost.
On GitHub, PHPMailer says "Compatible with PHP 5.0 and later", but that may not be the case.
Try changing your version of PHP to 5.5 and see if that fixes the problem. You can change your version of PHP by going to control panel and clicking on PHP Configuration.
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
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';
?>
`