I'm trying to send email to my gmail account from my website using mail() function. This is working fine but the problem is, when I receive the mail in my gmail account inbox ( not in spam ), there is a '?' mark instead of a regular blank profile picture. When I hover over the '?' mark, a message pops up saying,"Gmail couldn't verify that mywebsite.com actually sent this message (and not a spammer)". I have added two pictures of this issue. I contacted to my hosting provider and they told me that it was a script related issue. They analyzed the file which I got by clicking on "Show original" in my gmail inbox. They said that, the problem occurred because the 'from' email address that gmail got was "cpanel-username#server-hostname.com" instead of "myemail#website.com". I have to replace "cpanel-username#server-hostname.com" with "myemail#website.com". I tried a lot but was unable to change the "from" header. My code is something like this
$Email = "myemail#gmail.com";
$message = "Hello!!";
$headers = "From: Mywebsite <noreply#mywebsite.com>";
$sentmail = mail("$Email",'Something Important',"$message",$headers);
Note that, "noreply#mywebsite.com" is a real email address which I created in my cpanel. I also tried phpmailer to solve this issue but I did not succeed. My phpmailer code is like this
require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isMail(); // I also tried $mail->isSMTP(), but it does not work. Just keeps loading the page but never completes.
$mail->Host = 'localhost';
$mail->SMTPAuth = true;
$mail->Username = 'noreply#mywebsite.com';
$mail->Password = '****************';
$mail->SMTPSecure = 'tls';
$mail->Port = 365;
$mail->setFrom('noreply#mywebsite.com', 'Mywebsite');
$mail->addAddress('myemail#gmail.com');
$mail->isHTML(true);
$mail->Subject = 'Something Important';
$mail->Body = 'Hello!!';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
But this also does not solve my problem. The from header is still "cpanel-username#server-hostname.com" when the mail is received in gmail. Please someone help me with this issue.
you can add the -f user#domain.tld to a mail.force_extra_parameters line in your php.ini.
See the solution provided here. It helped me.
https://forums.cpanel.net/threads/email-sent-as-username-hostname.601655/
Related
I have a contact form made using PHPMailer. It has been working since today, then it suddenly stopped working. I tried to understand why and I discovered I get everytime error about the sender which is not allowed as it says. Here is the code:
try {
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtps.aruba.it';
$mail->SMTPAuth = true;
$mail->Username = 'info#mydomain.it';
$mail->Password = 'myPassword';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom("myemail#gmail.com", 'Sender'); // Here is where I put the sender email
$mail->addAddress('info#mydomain.it');
$mail->isHTML(true);
$mail->Subject = "Subject";
$mail->Body = "Body";
if (!$mail->send()) {
$result = array('status'=>"error", 'message'=>"Mailer Error: ".$mail->ErrorInfo);//
print_r(json_encode($result));
} else {
$result = array('status'=>"success", 'message'=>"Message sent.");
print_r(json_encode($result));
}
}
catch (Exception $e) {
echo "Error excpetion: ".$e;
}
Here is the error I get from the debug:
The following From address failed: myemail#gmail.com: MAIL FROM command
failed,<myemail#gmail.com> ik2dozQHmuz2mik2doPsAn - Mittente non
consentito / Sender not allowed ( mail from )
I tried to update PHPMailer, now I have the latest version. Also, I tried with an outlook.it email I have, but same error again.
It was perfectly working since today, can you help me?
Most likely the server admin has applied anti email spoofing policy today, so yesterday it works, but today it disallows you to send thru smtps.aruba.it as
sender 'xxxxx#gmail.com'
The proper way is to change your "from" address to info#mydomain.it, but if you want the recipient to reply your email but get it sent to xxxxx#gmail.com, then add the following
$mail->ClearReplyTos();
$mail->addReplyTo('xxxxx#gmail.com', 'your name in gmail');
Alternatively, use gmail smtp server to send out the email thru PHPMailer
(you may refer to the official link: https://support.google.com/a/answer/176600?hl=en for the smtp settings needed)
In case you have other problems in using gmail smtp, you may also wish to refer to this SO post (or other related ones)
PHPMailer does not work with Gmail SMTP
I've got an issue with PHPmailer getting stuck on my mail.php screen (usually it forwards the user to a success.html page). I've turned on error reporting, but still nothing shows up. I'm quite a noob at PHP, but it was working on my test URL before I moved it to the actual URL I wanted it to be on (just a few directories over on my server). Now I'm stuck on a white screen with no errors.
ALSO, I'm having an issue where on hotmail (and maybe some other providers--Gmail is working fine now) it's marking the emails as spam. I fixed a reverse DNS issue, but it's still marking the emails as spam. Any ideas on how to fix it? Please check my body and see if the content raises any red flags.
Here's the code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once('/var/www/includes/PHPMailer/PHPMailerAutoload.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
//gather variables from form//
$gmname = $_POST['gmname'];
$charname = $_POST['charname'];
$email = $_POST['email'];
$date = $_POST['date'];
$time = $_POST['time'];
$bantype = $_POST['radiogroup'];
$banreason = $_POST['banreason'];
//end gather//
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$body ="Attention account holder,<br \>This is a notice informing you that your Ashran account has been suspended. Please review the following information.<br \><br \>Account Name: $email<br \>Character Name: $charname<br \>Server: US - Grommash<br \>Ban Reason: $banreason<br \>Ban Type: $bantype<br \>Ban End Date: $date $time Server Time<br \>Banning staff member: $gmname<br \><br \>If you would like to appeal your ban because you feel that you were incorrectly punished, please follow the instructions in the following thread: Click Here<br \><br \>Do NOT reply to this email.";
//$body = eregi_replace("[\]",'',$body);//
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "----------#gmail.com"; // GMAIL username
$mail->Password = "----------"; // GMAIL password
$mail->SetFrom('----------#gmail.com', '------ -----');
$mail->AddReplyTo("---------#gmail.com","----- -----");
$mail->Subject = "Ashran - Account Suspension Notice";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "$email";
$mail->AddAddress($address);
//Sets URL for forward after completion
$url = 'success.html';
//
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
header( "Location: $url" );
echo "Ban notice sent!!!";
}
?>
For the spam folder issue: If you find you're in a process where you're tweaking your content and then checking if it fixed your delivery problems, you can use inboxtrail.com's seed-based email deliverability test to see which email providers are dumping you to the spam folder after each content change. It's probably a good idea to re-test all the top providers, since for all you know a content change that solves the problem on hotmail could create new problems on gmail or yahoo or something. This should also tell you if the way your email server is configured is setting off any red flags.
I am trying to change the sender address of the mail. Firstly I tried by gmail, then I let to know that by gmail its not possible now I am trying using Yahoo, and I got following error:-
SMTP ERROR: MAIL FROM command failed: 553 From address not verified.
Getting blank here I dont understand what do I do? Any help will be appreciated. following is my code:-
<?php
//date_default_timezone_set('Etc/UTC');
require('PHPMailerAutoload.php');
$mail=new PHPMailer();
$mail->CharSet = 'UTF-8';
$body = 'This is the message';
$mail->IsSMTP();
$mail->Host = "plus.smtp.mail.yahoo.com";
//$mail->Host = 'smtp.gmail.com';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Username = 'myyahooid#yahoo.com';
$mail->Password = 'xyz';
$name='Test Name';
$mail->Sender='thishavetoset#domain.com';
//$mail->From = 'sender#senderdomain.com';
//$mail->FromName = 'Sender Name';
$mail->SetFrom('thishavetoset#domain.com', $name, TRUE);
$mail->AddReplyTo('no-reply#mycomp.com','no-reply');
$mail->Subject = 'subject';
$mail->MsgHTML($body);
$mail->AddAddress('myyahooid#yahoo.com', 'title1');
//$mail->AddAddress('abc2#yahoo.com', 'title2'); /* ... */
$fileName='../rough/test.pdf';
$mail->AddAttachment($fileName);
//$mail->send();
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
Let me know another solution to set the sender name also if you think, it can't be done this way. Thanks a ton in advance.
The sender email you using should be real email id and as your using Yahoo mail i think then it must registered in yahoo
There are two reasons smtp trows such error are.
first is You are attempting to send email to a domain that is not recognized by this server
second is You are attempting to relay email through this server and have not authenticated
Check if $mail->Sender='thishavetoset#domain.com'; email is set for your domain name your using.
So try to use email which user email password your using.
$mail->Username = 'myyahooid#yahoo.com';
In Gmail you can add that email id as external address from accounts and import tab >> add another email address, You will need details of smtp from the Admin of hosting/domain and add the email id.
once you add the external email address you can use that email id as sender from gmail smtp.
I am having a unique issue (I did a thorough search on SO before I attempted to ask this question.
When I use the PHPMailer to send to a gmail (or hotmail, etc) address, it works great. As soon as I change it to send to a Google Apps email address, I don't get any error message instead it tells me it was successfull but no emails come through.
Has anybody seen this issue before? Is my code missing something very particular that makes it a valid email to pass through Google Apps Servers (not sure if I am heading in the right direction here). Thank you!
Start of my Code:
<?php
require("/PHPMailer_5.2.0/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Port = 465;
$mail->Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->Mailer = 'mail';
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = "******#dynamicsafetyfirst.com";
$mail->Password = "*******";
$mail->From = $_POST['email'];
$mail->AddAddress("someuser#gmail.com");
$mail->Subject = "First PHPMailer Message";
$mail->WordWrap = 50;
$mail->FromName = $_POST['name'];
$mail->Subject = $_POST['enquiry'];
$mail->Body = $_POST['comments']. "--By--".' name: '. $_POST['name']."--". 'email: ' .$_POST['email'];
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
END OF CODE.
You're putting in quite a lot of effort to do things wrong. First up you're using a pretty old version of PHPMailer - go get the latest from github. Next, your code has many issues, so start again using the gmail example provided. Use tls on port 587. Do not set Mailer - you've already called isSMTP(), and overriding Mailer later is asking for trouble.
To see what is going on set $mail->SMTPDebug = 3;, and it will show you the whole SMTP conversation. At that point you may get some clue as to what is happening to your message.
**> the mail posted with the below given is going to spam. I am not using
captcha in the form as i don want to. So can anybody help me to the
mail in Inbox**
<?php
if(isset($_POST['submit']))
{
$name = $_POST['Name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$date = $_POST['checkinDate'];
$package = $_POST['package'];
$person = $_POST['adults'];
$kids = $_POST['kids'];
$ip=$_SERVER['REMOTE_ADDR']; //trace the ip address of the user submited
$subject ="Query From :Kerala-Honeymoon-Packages - Promotion\n"; //subject of the email
$to="paul#roverholidays.com";
$cc="online#roverholidays.com";
$ccc="deepti#roverholidays.com";
$from=$_POST['email'];
$adc="Name :$name\n";
$adc.="Email :$email\n";
$adc.="Phone :$phone\n";
$adc.="Date of Travel :$date\n";
$adc.="Package :$package\n";
$adc.="Adults :$person\n";
$adc.="Kids :$kids\n";
$message ="$name copy of the query you submited in Kerala-Honeymoon-Packages";//message header to user submited
$headers="From: <".$from. ">" ;
mail($cc,$subject,$adc,$headers);
mail($ccc,$subject,$adc,$headers);
mail($email,$message,$adc);
header("Location: thanks.htm");
}
else
{
return false;
}
?>
coding-wise I don't think there is anything you can do because it is the email server that classifies your email as a spam not the way you coded your script. All you can do is to control it from the receiver email setting i.e you setup your gmail filters to detect that email based on keyword like "Kerala-Honeymoon-Packages" and move it out of spam.
I don't know for sure what the email servers algorithms are for marking email as spam. However, I think sending email from different domain rather than your domain name is likely to be detected as phishing email. what I mean is when someone put his/her yahoo email in the form and click on send, your server will send the email to emails addresses in the script but it will send it as if it came from yahoo, which will be suspicious for the receiver email server as it knows that it did not come from yahoo.
Many email services block mail sent directly from random servers because they have little to no reputation as a legitimate source of non-spam emails. Instead of using the straight php mail() function, try using a SMTP service like Mandrill or Gmail's SMTP service. Both are free.
Here is the configuration page for Mandrill:
http://help.mandrill.com/entries/23737696-How-do-I-send-with-PHPMailer-
<?php
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com'; // Specify main and backup server
$mail->Port = 587; // Set the SMTP port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'MANDRILL_USERNAME'; // SMTP username
$mail->Password = 'MANDRILL_APIKEY'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from#example.com';
$mail->FromName = 'Your From name';
$mail->AddAddress('josh#example.net', 'Josh Adams'); // Add a recipient
$mail->AddAddress('ellen#example.com'); // Name is optional
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';