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
Related
I have made a website on my localhost. After everything was ready to go I hosted the website. However, now PHPMailer seems to cause the trouble. Mails are not sending and it seems like PHP code does not execute after $mail = new PHPMailer command. Here is part of the code:
if($conn->query($sql)){
require_once '/home/ziptie/public_html/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = true;
$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'; // your email id
$mail->Password = 'mypassword'; // your password
$mail->SMTPSecure = 'tls';
$mail->Port = 587; //587 is used for Outgoing Mail (SMTP) Server.
$mail->setFrom('mygmail#gmail.com', 'ZIPTIE');
$mail->addAddress($email); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$v="http://ziptie.rs/verification-page.php?sifra=$token";
$body = file_get_contents('/home/ziptie/public_html/verificationemail.html');
$body = str_replace('promenljiva', $v, $body);
$mail->Subject = 'Verifikacija kupca, ZIPTIE';
$mail->Body = $body;
$mail->addAttachment("naruzbine ".date("d-m-Y").".zip");
$mail->send();
header("Refresh:0; url=https://www.ziptie.rs/verification-page.php");
//echo '<script>alert("Verifikacioni link je poslat, proverite Vašu mejl adresu.")</script>';
/*if(!$mail->send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}*/
}
else{
echo $conn->error;
}
Does anybody know the solution? Thanks!
found solution in upgrading to PHPMailer 6.3
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 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.
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!";
}