i am using xampp version 1.8.1 and i have also removed semicolon from php.ini file in extension=php_openssl.dll but still I am getting this error stream_socket_enable_crypto(): this stream does not support SSL/crypto and Message could not be sent.Mailer Error: SMTP connect() failed.
My php mailer code is:
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'urusername#gmail.com';
$mail->Password = '********';
$mail->SMTPSecure = 'tls';
$mail->From = 'urusername#gmail.com';
$mail->FromName = 'Example';
$mail->addAddress('receivermail#gmail.com', 'xxxxx');
$mail->addReplyTo('receivermail#gmail.com', 'xxxxxx');
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = 'Using PHPMailer';
$mail->Body = 'Hi Iam using PHPMailer library to sent SMTP mail from localhost';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
?>
kindly help me
Set the port to:
$mail->Port = 587;
Google SMTP uses port 587.
Related
I have been searched many hours to solve my problem and i failed.
This is my simple code use PHPMailer to send email with Gmail in xampp and get this error each time:
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
and this is my php code :
<?php
require_once('PHPMailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->HOST = 'smtp.gmail.com';
$mail->PORT = '465';
$mail->isHTML();
$mail->Username = '##myemail###gmail.com';
$mail->Password = '##mypass##';
$mail->SetFrom('no-reply#howcode.org');
$mail->Subject = 'Hello World';
$mail->Body = 'A test email!';
$mail->AddAddress('hamidreza.mohammadian#yahoo.com');
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
please help me.
Add this $mail->SMTPDebug = 3; $mail->isHTML(true); to output debug. But make sure you have activated connection by insecure apps using Gmail. Look a this link https://support.google.com/a/answer/6260879?hl=en
<?php
include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->SMTPDebug = 2;
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->Port = 587; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Username = "123#gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "123#gmail.com";
$mail->FromName = "Webmaster";
$mail->AddAddress("asd#hotmail.com");
$mail->AddReplyTo("123#gmail.com", "Webmaster");
$mail->IsHTML(true);
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
It returns an error
2016-04-01 08:41:43 SMTP ERROR: Failed to connect to server: (0)
2016-04-01 08:41:43 SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message was not sent.Mailer error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I am hosting this php on my xampp local server. The extension=php_openssl.dll on php.ini is already uncommended.
Your configuration might be wrong. I believe that if you change your host into smtp.gmail.com it might solve your problem.
I noticed that you set security tls but you want to connect with ssl as well.
Change $mail->Host = "ssl://smtp.gmail.com"; into $mail->Host = "smtp.gmail.com"; and security to ssl.
From this answer:
$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 = "email#gmail.com";
$mail->Password = "password";
$mail->SetFrom("example#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("email#gmail.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
I am trying to use PHPMailer to send e-mails over SMTP but so far I have had no luck. I have gone through a number of questions, PHPMailer tutorials and forum posts but I still cannot find a way to get it to work. I'm still getting an error Message could not be sent.Mailer Error: SMTP connect() failed.
Here is the code:
<?php
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = 'myemail#gmail.com';
$mail->Password = '************';
$mail->Port = "995";
$mail->From = 'myemail#gmail.com';
$mail->FromName = 'Tim Cullen';
$mail->addAddress('james#example.com', 'James Johnson');
$mail->addReplyTo('myemail#gmail.com', 'Tim Cullen');
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = 'Using PHPMailer';
$mail->Body = 'Hi Iam using PHPMailer library to sent SMTP mail from localhost';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo "EMail has been sent!";
//echo 'Message saved to Send folder!';
?>
You can try SMTPDebug to see what is actually happening
$mail->SMTPDebug = 2;
It looks like you're using the wrong port. Try 465 and open that port up.
iptables -A INPUT -p tcp --dport 465 -j ACCEPT
i want to send an email from localhost to gmail, but it says "SMTP connect() failed"
here is my code. I've also tried to change configuration php.ini and sendmail.ini but no luck.
Thank you.
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'asd#gmail.com';
$mail->Password = 'password';
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('asd#gmail.com');
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = 'Email'
$mail->Body = "This is body";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Try out the following :
Ensure that the PHPMailer library is included in the code.
Ensure that you are internet connection from localhost is not inhibited by any proxy.
Happy Coding :)
check the line $mail->Subject = 'Email' for a missing ;
I am trying to send email through PHPMailer. And while sending it gives me error as
SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed. Mailer Error: SMTP connect() failed.
I really can't figure it out what's wrong. Is it the server configuration problem or code configuration problem. If anyone knows the answer please let me know.
Code below:
require_once('class.phpmailer.php');
include('class.smtp.php');
$mail = new PHPMailer(); //Initialize a new PHPMailer object;
$body = eregi_replace("[\]",'',$body); //Replace unwanted characters of the content
$mail->CharSet ="ISO-8859-1";
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->From = 'email';
$mail->FromName = 'name';
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = 'smtp.live.com';
$mail->Port = '465';
$mail->Username = 'email ';
$mail->Password = 'password';
$mail->SetFrom('email', 'who');
$mail->AddReplyTo('email','who');
$mail->Subject = $subject;
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, '');
if(!$mail->Send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo "Message sent successfully!";
}