Sending email getting error as Could not connect to SMTP host - php

I have implemented mail functionality to my website but getting error while sending email.I have added PHPMailer to my website and added code but getting this error. Changed with host as well by checking in google but still getting the same error.
2019-07-06 06:55:56 CLIENT -> SERVER: EHLO website.com
2019-07-06 06:55:56 CLIENT -> SERVER: STARTTLS
SMTP Error: Could not connect to SMTP host.
2019-07-06 06:55:56 CLIENT -> SERVER: QUIT
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
<?php
if(isset($_POST['submit_contact']))
{
require 'PHPMailer/PHPMailerAutoload.php';
$to = "XXXX#gmail.com";
$name = $_POST['firstname'];
$email = $_POST['email'];
$contact=$_POST['contact'];
$textarea = $_POST['textarea'];
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = false;
$mail->SMTPSecure = 'none';
$mail->Host = "localhost";
$mail->Port = 25;
$mail->IsHTML(true);
$mail->Username = "XXXXX#gmail.com";
$mail->Password = "PASSXXX";
$mail->SSL=False;
$message = array();
$message[]= 'Name : '.trim($name).' ';
$message[]='Phone : '.trim($contact).' ';
$message[]='Email : '.trim($email).' ';
$message[]='Message : '.trim($textarea).' ';
$message = implode('<br/>', $message);
$mail->SetFrom($email);
$mail->Subject = 'Regarding Pure Gir Cow Milk';
$mail->Body = $message;
$mail->AddAddress($to);
if(!$mail->send()) {
$msg = "Error while sending email";
$msgclass = 'bg-danger';
} else {
$msg = 'Successfully Sent.';
$msgclass = 'bg-success';
}
}
?>

This solved my issue.
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'none';
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "xxxx#gmail.com";
$mail->Password = "xxxxx";
$from = $email; // Reply to this email
$mail->From = $from;
$mail->FromName = $name;

Related

PHPMailer is not working on godaddy server

I have developed a site in PHP and added a PHPMailer function for my contact us page but the mailer functionality is not working. Contacted with support team but they didn't help me tried a lot with that.
<?php
if(isset($_POST['submit_contact']))
{
require 'PHPMailer/PHPMailerAutoload.php';
$to = "gmail#gmail.com";
$name = $_POST['uname'];
$email = $_POST['email'];
$phone = $_POST['phonenumber'];
$companyname = $_POST['companyname'];
$country = $_POST['country2'];
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "relay-hosting.secureserver.net";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "xxxx#gmail.com";
$mail->Password = "PASSword1#3";
$message = array();
$message[] = 'Name : '.trim($name).' ';
$message[]='Phone : '.trim($phone).' ';
$message[]='Email : '.trim($email).' ';
$message[]='Company Name : '.trim($companyname).' ';
$message[]='Country : '.trim($country).' ';
$message = implode('<br/>', $message);
$mail->SetFrom($email);
$mail->Subject = 'Here is the subject';
$mail->Body = $message;
$mail->AddAddress($to);
if(!$mail->send()) {
$msg = "Error while sending email";
$msgclass = 'bg-danger';
header("Location: /");
die();
}
else {
$msg = 'A mail with recovery instruction has sent to your email.';
$msgclass = 'bg-success';
}
}
?>
u used gmail,u should set host to smtp.gmail.com, SMTPSecure to ssl,SMTPAuth to true,port to 465,u alse should use the app password,that u can see https://support.google.com/mail/answer/7126229
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = false;
$mail->SMTPSecure = 'none';
$mail->Host = "localhost";
$mail->Port = 25;
$mail->IsHTML(true);
Solved the issue with this update in SMTP

I used phpmailer() concept to receive mail from users from my bigrock server using php script, but It's not working

This is my code:
<?php
require_once "PHPMailer/PHPMailerAutoload.php";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com"; //gethostbyname('smtp.gmail.com');
$mail->SMTPAuth = true;
$mail->SMTPDebug = 3;
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->Username = "ku***wa***ar***#gmail.com";
$mail->Password = "t***r9***5******7";
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress($mail->Username);
$mail->Subject = 'Contact form query / feedback';
$mail->Body = "
<div><span>Name : </span><span>{$name}</span></div>
<div><span>Email : </span><span>{$email}</span></div>
<div><p>{$message}</p></div>
";
$mail->isHTML(true);
if ($mail->send()){
echo "Your feedback/query is sent!";
}else{
echo "Error! Unable to forward your request.<br> Pleas try again later!";
}
Note: I have used " GMail " as my SMTP server and SMTPSecure is " ssl " and port is "465" and username & passwords are my GMail username & password
The Error Message is:
Screen Shot : https://s16.postimg.org/4hgsh9d51/smtp.png
Here is your code modified
<?php
include "PHPMailer_5.2.4/class.phpmailer.php";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com"; //gethostbyname('smtp.gmail.com');
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->isHTML(true);
$mail->Username = "hari.andoidsaiss#gmail.com";
$mail->Password = "supreme#12#";
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress($mail->Username);
$mail->Subject = 'Contact form query / feedback';
$mail->Body = "
<div><span>Name : </span><span>{$name}</span></div>
<div><span>Email : </span><span>{$email}</span></div>
<div><span>Message : </span><p>{$message}</p></div>
";
if ($mail->send()){
echo "Your feedback/query is sent!";
}else{
echo "Error! Unable to forward your request.<br> Pleas try again later!";
}

While sending mail getting following error

<?php
require('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Username = "akilesh1111#gmail.com";
$mail->Password = "*********";
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->SetFrom($_POST["userEmail"], $_POST["userName"]);
$mail->AddReplyTo($_POST["userEmail"], $_POST["userName"]);
$mail->AddAddress("akilesh1111#gmail.com");
$mail->Subject = $_POST["subject"];
$mail->WordWrap = 80;
$mail->MsgHTML($_POST["content"]);
if(is_array($_FILES)) {
$mail->AddAttachment($_FILES['attachmentFile']['tmp_name'],$_FILES['attachmentFile']['name']);
}
$mail->IsHTML(true);
if(!$mail->Send()) {
echo "<p class='error'>Problem in Sending Mail.</p>";
} else {
echo "<p class='success'>Contact Mail Sent.</p>";
}
?>
This code is working fine in localhost
When uploading to server then it shows below error
SMTP Error: Could not authenticate. Problem in Sending Mail.

I can't connect my SMTP server for phpmailer

I want to send an email through the website I created but i can't connect with SMTP server with any port. I use windows 8.1, does it matter? If yes, please tell me how to setting SMTP server.
This is my code :
IF(isset($_POST['reply_button']))
{
$tmpEmail=$_POST['email'];
$tmpName=$_POST['name'];
$tmpContent=$_POST['content'];
$message = file_get_contents('mailTamplate/replyMessage.html');
$message = str_replace('%name%', $tmpName, $message);
$message = str_replace('%content%', $tmpContent, $message);
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->Username = "example#gmail.com";
$mail->Password = "password";
$mail->AddAddress($tmpEmail);
$mail->FromName = "Example";
$mail->AddEmbeddedImage('./images/logo.jpg', 'my-image', 'attachment', 'base64', 'image/jpeg');
$mail->Subject = $tmpName;
$mail->MsgHTML($message);
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
if(!$mail->Send())
echo "Mailer Error: " . $mail->ErrorInfo;
else
{
echo "Message has been sent";
}
}

PHP mailer not working with client gmail id

I am new in php i have a problem with my php mailer when i set
$Host = 'ssl://smtp.googlemail.com';
$Username = 'my gamil id';
$Password = 'my gmail password';
$Port = 465;
Php mailer working fine, but when i change it to
$Host = 'ssl://smtp.googlemail.com';
$Username = 'client gamil id';
$Password = 'client gmail password';
$Port = 465;
mailer not working and its shows an error message
Authentication Required
I am from India and client from US, so is there any changes in configuration file?
Please help me
Here is my mailer.php file
include 'phpmailer/class.config.php';
include 'phpmailer/class.phpmailer.php';
include 'phpmailer/class.smtp.php';
session_start();
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->IsHTML();
$mail->SMTPAuth = true;
if (MailConfig::$Debug) {
$mail->Host = MailConfig::$DebugHost;
$mail->Username = MailConfig::$DebugUsername;
$mail->Password = MailConfig::$DebugPassword;
} else {
$mail->Host = MailConfig::$Host;
$mail->Username = MailConfig::$Username;
$mail->Password = MailConfig::$Password;
}
$Subject = "Payment Received";
//////
/////////////
if (MailConfig::$Debug)
$receipientEmail = "client#example.com";
else
$receipientEmail = "client#example.com";
$Body = "A payment of $ " . $_POST['payment'] . " has been credited in your account";
$mail->AddAddress($receipientEmail);
$mail->Subject = $Subject;
$mail->Body = $Body;
Thanks
Your Host is incorrect . It should be:
$host = 'mail.gmail.com';
and the code is:
$mail = new PHPMailer();
$mail->IsHTML();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the server
$mail->Host = MailConfig::$Host; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = MailConfig::$Username; // GMAIL username
$mail->Password = MailConfig::$Password;
Note the SMTPSecure line

Categories