PHPMailer is not working on godaddy server - php

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

Related

Sending email getting error as Could not connect to SMTP host

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;

Using SMTP to send emails in PHP getting blank pge

I am trying to send emails using SMTP Server in Core HP. I am getting a blank page not displaying any errors. Can any one help me out? what i am doing wrong? Unable to check the issue as well!
<?php ob_start();
if(isset($_POST['submit_contact'])) {
require 'PHPMailer/PHPMailerAutoload.php';
$to = "abc#gmail.com";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$txt = $_POST['comment'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "abc#gmail.com";
$mail->Password = "password1#3";
$mail->SetFrom('$email');
$mail->Subject = $subject;
$mail->Body = $txt;
$mail->AddAddress($to);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
}
?>
is your source code located at public_html folder?
In that case you have to include like below
require 'aaa/PHPMailer/PHPMailerAutoload.php';

Mail configuration error in amazon hosting using php?

I designed my website and hosted on my amazon ec2 instance and I bought my domain in godaddy (www.mydomain.com).Now I want a mail configuration in my contact form page in website.. Below its my code , I don't know where am I mistake the code?
<?php
if(isset($_REQUEST['submit']))
{
try
{
$name = $_POST['name'];
echo "<script type='text/javascript'>alert('$name')
</script>";
$email = $_POST['email'];
echo "<script type='text/javascript'>alert('$email')
</script>";
$subject = $_POST['subject'];
echo "<script type='text/javascript'>alert('$subject')
</script>";
$message = $_POST['message'];
echo "<script type='text/javascript'>alert('$message')
</script>";
$response ="";
$body = <<<EOD
<div style='font-size:18px'>
<b> Name </b> : $name <br />
<b> Email address </b> : $email <br />
<b>Message </b> : $message <br />
</div>
EOD;
$to = "XXXXX#gmail.com";
require_once($_SERVER['DOCUMENT_ROOT'].'/samplemail/lib/class.phpmailer.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/samplemail/lib/class.smtp.php');
$mail = new PHPMailer(true);
//$mail->Host = "relay-hosting.secureserver.net"; // your SMTP Server
// echo $res;
$mail->IsSMTP();
$mail->Host = "email-smtp.us-east-1.amazonaws.com";
$mail->SMTPDebug=true;
$mail->SMTPAuth = true; // Auth Type
$mail->Port = 25;
$mail->IsSendmail();
//$mail->SMTPSecure = "ssl";
$mail->Username = "support#mydomain.com";
$mail->Password = "******";
$mail->Sender = "supportexample#mydomain.com";
$mail->From = "supportexample#mydomain.com";
$mail->AddReplyTo($email);
$mail->FromName = "Example";
$mail->AddAddress($to);
//$mail->AddAddress("desired recipient no.2 optional");
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body=$body;
$mail->WordWrap = 50;
$mail->Send();
echo "<script type='text/javascript'>alert('Mail Send Successfully')
</script>";
}
catch (phpmailerException $e) {
echo "<script type='text/javascript'>alert('Failed')
</script>";
echo $e->errorMessage();
}
}
?>
It gives an error
Could not execute: /var/qmail/bin/sendmail
Try This One. This Might Helpful. You Have To Use Different Email For From Mail.
Instead Of Using
$mail->From = "support#mydomain.com"
You Have To Use Another Email Here :
$mail->From = "supportexample#mydomain.com";
require_once('phpmailer/class.phpmailer.php');
require_once('phpmailer/class.smtp.php');
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = "email-smtp.us-east-1.amazonaws.com"; // SMTP HOST
$mail->SMTPAuth = true;
$mail->Username = "support#mydomain.com"; // SMTP username
$mail->Password = "********"; // SMTP password
$mail->SMTPSecure = "ssl"; // Enable TLS encryption, `ssl` also accepted
$mail->Port = "465"; // TCP port to connect to 587
$mail->From = "supportexample#mydomain.com";
$mail->FromName = "Domain Example";
$mail->addAddress("XXXX#gmail.com");
$mail->addReplyTo("supportexample#mydomain.com");
$mail->isHTML(true);
$mail->Subject = "Hello Test";
$mail->Body = "Test Message Working With Us";
if($mail->send()){
return true;
}
else{
return $mail->ErrorInfo;
}

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!";
}

How to use phpMailer isSMTP on Bluehost?

It's taken me days to get the right settings so I thought I would post a php script that works on Bluehost. In initial tests using isSMTP is faster than isMAIL.
<?php
require_once '../includes/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "box1311.bluehost.com"; // specify bluehost as outgoing server
$mail->SMTPSecure = "tls"; // sets the prefix to the server do not use ssl
$mail->SMTPDebug = 3; // comment out if you don't need debug info
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "USER#EXAMPLE.COM"; // SMTP username (your email account)
$mail->Password = "PASSWORD"; // SMTP password
$mail->Port = 25;
$mail->From = 'USER#EXAMPLE.COM';
$mail->FromName = "USER#EXAMPLE.COM";
$mail->AddAddress('CLIENT#gmail.com');
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = 'test message';
$body = '<!DOCTYPE html>
<html><header>
</header>
<body lang=EN-US>
<div style="text-align:center">
<h2>this is a test</h2>
</div>
</body>
</html>';
$mail->Body = $body;
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send()){
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo '<h1>message sent</h1>';
}
?>
This code work for me.
include "phpmailer/class.phpmailer.php";
include "phpmailer/class.smtp.php";
$email_user = "email#host.com";
$email_password = "pass123";
$the_subject = "Title";
$from_name = "Sender";
$phpmailer = new PHPMailer();
// ---------- datos de la cuenta de correo -----------------------------
$phpmailer->Username = $email_user;
$phpmailer->Password = $email_password;
//---------------------------------------------------------------------
$phpmailer->SMTPSecure = 'tls';
$phpmailer->Host = "box6171.bluehost.com";
$phpmailer->Port = 26;
//$phpmailer->SMTPDebug = 2;
$phpmailer->IsSMTP();
$phpmailer->SMTPAuth = true;
$phpmailer->setFrom($phpmailer->Username,$from_name);
$phpmailer->AddAddress("to#host.com");
$phpmailer->Subject = $the_subject;
$phpmailer->Body .="<h1 style='color:#3498db;'>Attachment:</h1>";
$phpmailer->Body .= "<h3>".$attach1."</h3>";
$phpmailer->AddAttachment($attach, "attach1");
$phpmailer->AddBCC("hidecopy#host.com", "bcc1");
$phpmailer->IsHTML(true);
$enviado = $phpmailer->Send();
if($enviado) {
echo 'email send successful';
}
2022 update
$phpmailer->Host = [your fully qualified domain]
$phpmailer->Port = 465
$phpmailer->SMTPSecure = 'ssl'
Important that $phpmailer->From and $phpmailer->Username must be the same.

Categories