<?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.
Related
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;
While running the PHPMailer in localhost mail will be sending but while hosting the PHPMailer shows the error as SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting. please help me.
here is my code
<?php
//include PHPMailerAutoload.php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'mail#gmail.com';
$mail->Password = 'password';
$mail->setFrom('mail#gmail.com', 'mail');
$mail->addAddress('mail#gmail.com');
$mail->Subject = 'SMTP email test';
$mail->Body = 'Thanks for commenting';
if ($mail->send())
echo "mail is sent";
else
echo $mail->ErrorInfo;
?>
Ok let's make it clearly :
Make sure your SMTP Port code is same with SMPT port in your host
Auth to your account is not wrong
Check phpmailer class are success to call like vardump or something else
Sample of my Code :
require(https://example.com/PHPMailerAutoload.php');
require(https://example.com/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'mail.example.com';
$mail->SMTPAuth = TRUE;
$mail->Username = 'customer_service#example.com';
$mail->Password = 'blablabla';
$mail->From = 'customer_service#example.com';
$mail->setFrom('customer_service#example.com', 'My Cool Website');
$mail->AddAddress('recipient#destination.com', 'Recipient Full Name');
$mail->WordWrap = 70;
$mail->Subject = 'PHP Mailer';
$mail->Body = 'Awesome';
$mail->IsHTML(TRUE);
I am obtaining two email id's from database by a query. Both stored in a single variable. I want to send email to these two addresses by PHPMailer keeping them in cc. Currently only one email is being selected and passed in cc. Can I know where am I going wrong. My code here,
$get_cc_email_id_sql=mysql_query("select * from tbl_name where column_name IN(13,5)");
$user_email_cc='';
while ($get_data_cc=mysql_fetch_array($get_cc_email_id_sql))
{
$user_email_cc=$get_data_cc['email'];
}
$mail = new PHPMailer();
$subject = "Mail";
$content ="XYZ";
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "ssl";
$mail->Debugoutput = 'html';
$mail->Port = 465;
$mail->Username = "xyz#xyz.com"; // Changed username and password from
$mail->Password = "xyz";
$mail->Host = "ssl://smtp.xyz.com";
$mail->Mailer = "smtp";
$mail->SetFrom("xyz#xyz.com", "XYZ");
$mail->AddAddress(abc#abc.com);
$mail->AddCC($user_email_cc);
$mail->Subject = $subject;
$mail->WordWrap = 80;
$mail->MsgHTML($content);
$mail->IsHTML(true);
if(!$mail->Send())
echo "Problem sending mail.";
else
echo "Mail Sent";
use this code
$mail->AddCC('person1#domain.com', 'Person One');
$mail->AddCC('person2#domain.com', 'Person Two');
use $user_email_cc as array then it will store you both email a 0 and 1 position
$user_email_cc=array();
while ($get_data_cc=mysql_fetch_array($get_cc_email_id_sql))
{
$user_email_cc[] =$get_data_cc['email'];
}
New Code
$get_cc_email_id_sql=mysql_query("select * from tbl_name where column_name IN(13,5)");
$user_email_cc=array();
while ($get_data_cc=mysql_fetch_array($get_cc_email_id_sql))
{
$user_email_cc[] =$get_data_cc['email'];
}
$mail = new PHPMailer();
$subject = "Mail";
$content ="XYZ";
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "ssl";
$mail->Debugoutput = 'html';
$mail->Port = 465;
$mail->Username = "xyz#xyz.com"; // Changed username and password from
$mail->Password = "xyz";
$mail->Host = "ssl://smtp.xyz.com";
$mail->Mailer = "smtp";
$mail->SetFrom("xyz#xyz.com", "XYZ");
foreach($user_email_cc as $email_cc){
$mail->AddCC($email_cc);
}
$mail->AddAddress(abc#abc.com);
$mail->Subject = $subject;
$mail->WordWrap = 80;
$mail->MsgHTML($content);
$mail->IsHTML(true);
if(!$mail->Send())
echo "Problem sending mail.";
else
echo "Mail Sent";
Can you call $mail->AddCC(...) multiple times, just like $mail->AddAddress(...)?
SMTP -> ERROR: DATA not accepted from server: 550 This message was classified as SPAM and may not be delivered
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.cc.com";
$mail->SMTPAuth = true;
$mail->Username = "info#cc.com";
$mail->Password = "cc";
$mail->From = "cc.com"." <info#cc.com>";
$mail->AddReplyTo("cc1#gmail.com");
$mail->FromName = "info#cc.com";
$mail->AddAddress($climail);
$mail->AddCC("cc1#gmail.com");
$mail->Sender="info#cc.com";
$mail->IsHTML(true);
$mail->WordWrap = 70;
$mail->Subject = $sub;
echo $meegate;
$mail->Body=$meegate;
$mail->SMTPDebug = 1;
$mail->Send();
Error occurring while sending mail.. mail not sent..
You need to set SMTP host and also the port I guess which is 465:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "info#gmail.com";
$mail->Password = "cc";
$mail->From = "gmail.com"." <info#gmail.com>";
$mail->AddReplyTo("cc1#gmail.com");
$mail->FromName = "info#gmail.com";
$mail->AddAddress($climail);
$mail->AddCC("cc1#gmail.com");
$mail->Sender="info#gmail.com";
$mail->IsHTML(true);
$mail->WordWrap = 70;
$mail->Subject = $sub;
echo $meegate;
$mail->Body=$meegate;
$mail->SMTPDebug = 1;
$mail->Send();
I want to send mail with php my codes are these;
<?php
include 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = 'mertcankarayilan#gmail.com';
$mail->Password = '*******';
$mail->SetFrom($mail->Username, 'Pegasus Havayolları?');
$mail->AddAddress('mertcankarayilan#hotmail.com', 'mertcankarayilan');
$mail->CharSet = 'UTF-8';
$mail->Subject = 'Ekomak';
$content = 'mailde yazan';
$mail->MsgHTML($content);
if($mail->Send()) {
echo "<script>window.location.href='islem-basari.php#gosterb';</script>";
} else {
echo 'Mail gönderilirken bir hata oluştu: ' . $mail->ErrorInfo;
}
?>
and I see a error like this:
The following From address failed: mertcankarayilan#gmail.com : MAIL not accepted from server
SMTP server error: 5.7.0 Must issue a STARTTLS command first. k6sm56314517eep.17 - gsmtp
you must enter method 'TLS':
$mail->SMTPSecure = "tls";