Hi I have a problem with my script sending emails out. Basically my script sends an email out like this:
From: zyz#yahoo.com
to: order#abc.ca
Even though the script is being sent out from #abc domain (Similiar to how gmail users send yahoo emails out from their account).
I get this message back from my server log:
550-5.7.1 Unauthenticated email from yahoo.com is not accepted due to domain's 550-5.7.1 DMARC policy.
Is there a way to bypass this with $config settings? Using a different smtp outgoing server?
Here is my email code:
$config['wordwrap'] = FALSE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$a=$this->load->view('cart/email',$data,true);
$this->email->from($data['email'], $data['fname'].' '.$data['lname']);
$this->email->to('order#abc.ca');
$this->email->subject('Your Order');
$this->email->message($a);
$this->email->send();
echo $this->email->print_debugger();
You should consider adding an SPF record with your domain name provider.
http://en.wikipedia.org/wiki/Sender_Policy_Framework
Your mail server neither conforms to Yahoo's DKIM nor is listed in the SPF record for yahoo.com, so the receiving mail server does not accept your message.
Your options to fix this include:
get Yahoo to add your IP to the SPF record (not likely)
have your server use your credentials to send the mail through Yahoo's outbound mail server https://answers.yahoo.com/question/index?qid=20120221123159AAYqXz1
use a from address in a domain that does not use SPF/DKIM
use a from address in the #abc domain and use the abc domain outbound mail server
Related
I will be using G Suite (formally Google Apps) to host the email of a site that runs off a separate host.
However, there is a contact form on the website, I haven't looked at it yet, but I assume it will use the standard mail() function.
As I understand it mail() will still use the servers mail server to send the mail, it may be a dumb question, but I assume this won't cause any spam detection issues because of this? Like, I know some servers won't accept mail if the From and/or Sender headers don't match the server it is coming from (or in some cases if the email you set in these headers doesn't exist).
So, if the mail is hosted on G Suite, and the email address that is setup in the From/Sender headers exists on G Suite this won't cause any issues correct?
Lastly, I know it's probably a better idea to use SMTP to send the mail via Google, but I may not have that choice, so I wanted to find out the answer to the above just in-case.
Edit: As per Nima's answer, is this something that can be avoided, or only with using Googles SMTP server to send with?
If you want it simple, then simple use SMTP.
Because of spam, multiple mail server provider are blocking mails from mail servers that have no correct RDNS (Reverse DNS) and MTA name configured.
You want to make sure that all three names are matching according to your MX Record:
Sender Hostname (e.g *mail#demohost.com, note that from can be what ever you want)
MTA-Name/HELO-Hostname (Configured in Mailserver, e.g demohost.com)
RDNS (Basicly it gives per IP-Adress the Hostname (e.g 42.42.42.42 -> demohost.com)
Also make sure your php.ini has the correct configuration for your Mail Server. Congrats you can now send Mails using mail(...).
As I said, it's probably most simple by just using SMTP. Assign the hard work to a hoster.
When you use GSUITE for hosting emails, it's obvious that you will be providing some domain name to GSUITE.
Now emails are marked spam and not spam based on the content as well as certificates of sending server and sending servers have different services for Transactional and Marketing Oriented emails. And GSUITE only provide transactional mail service, and transactional mails from a mail service --having valid certificates and not black listed-- lands directly into Inbox or Other Label, but Spam/Promotion.
Now GSUITE is having all correct certificates and I don't think there is any consumer oriented mail service provider, which blocks emails coming from google servers.
Other Question:-
Does the From Address in E-MAIL headers matters?
Upto now I have never seen from address impacting anything on receiving servers, but some consumer mail services block the usage of from address other than the account email address, just like mobile operators don't let us use someone else's caller id(Ideally).
But mail service providers to businesses let you use any address as from value in e-mail headers.
Edit:-
If you are still unsure about delivery of emails, you can use replyTo header with out any problem.
PS:- I have tested this myself with thousands of emails but using SendGrid servers.
http://php.net/manual/en/function.mail.php
The Windows implementation of mail() differs in many ways from the
Unix implementation. First, it doesn't use a local binary for
composing messages but only operates on direct sockets which means a
MTA is needed listening on a network socket (which can either on the
localhost or a remote machine).
On linux the sendmail executable is used to talk to the SMTP server configured on windows you can / could configure mail() function to use SMTP
So the best way is to use SMTP directly to send the email to Gmail to send the email.
Taken from:
https://stackoverflow.com/a/33506709/623150
Here is a way to do it with PHP PEAR
// Pear Mail Library
require_once "Mail.php";
$from = '<your#mail.com>'; //change this to your email address
$to = '<someone#mail.com>'; // change to address
$subject = 'Insert subject here'; // subject of mail
$body = "Hello world! this is the content of the email"; //content of mail
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'your#gmail.com', //your gmail account
'password' => 'snip' // your password
));
// Send the mail
$mail = $smtp->send($to, $headers, $body);
If you use gmail smtp remember to enable SMTP in you gmail account,
under settings
On a Linux Server you can't use SMTP via the mail function.
After setting up SPF Record i still am here to verify why i cannot recieve this email to hotmail account. I am able to send it to gmail with no issues. Please confirm if the code is correct, and SPF record is correct:
<?php
require_once 'PHPmailer/class.phpmailer.php';
$mail = new PHPMailer();
$body = "Thankyou for your Purchase. <br/><br/> Here is your Policy! You are now Protected during your Travels.";
$mail->AddAddress('$payer_email');
$mail->From = "noreply#example.com";
$mail->FromName = "Name";
$mail->Subject = "Thankyou for Your Purchase";
$mail->MsgHTML($body);
$mail->AddAttachment("tosend/xxx.pdf");
if(!$mail->Send()) {
echo "There was an error sending the message";
$sql = "UPDATE purchases SET policy_sent = 'Not Sent' WHERE id = '$lastid' ";
$stmt = $mysqli->query($sql);
$mysqli->close();
exit;
}
echo "Message was sent successfully";
$sql = "UPDATE purchases SET policy_sent = 'Sent', email_to = '$payer_email' WHERE id = '$lastid'";
$stmt = $mysqli->query($sql);
$mysqli->close();
?>
Here is the SPF:
v=spf1 a mx include:secureserver.net ~all
Are all these correctly configured?
Use SMTP Auth, then Hotmail wouldn't complain anymore. Anonymous mails are considered as spam by almost all receiving servers.
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port
$mail->Username = "yourname#yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
But ofc. depending on whether you have control over your SMTP or not, you should make sure, that basic stuff like reverse-dns-lookup is setup properly
Due to the discussion in the comments, I want to add a little bit more information about my thinking about why SMTP Auth will fix this:
IF you are using PHPMailer without the definition of an SMTP-Server, PHPMailer will operate in mail mode, which will just call the mail() function of php.
The mail-function itself will use the smtp-settings configured in the PHP-INI file, or the default values, which are listed here: http://php.net/manual/en/mail.configuration.php
defaults:
SMTP = "localhost"
smtp_port = "25"
Since the OP has configured a local mail server (or why would he setup MX-records?), php will now connect to this SMTP-Server without Authentication. The Server will accept the message and send it to the next server.
(Same applies if unix' sendmail is used)
Each Server in the chain and especially the receiving server can now see, that a private SMTP has been used and no Authentication has been provided.
That is already Spam-Score over 9000 because with a setting like that (theoretically) everyone could use that server to send mails!
Restrictions like only from localhost are ofc. not known by other servers, therefore that SMTP is considered to be an Open Mail Relay http://en.wikipedia.org/wiki/Open_mail_relay
Switching PHPMailer to SMTP-Auth (EVEN if still the local SMTP Server is used) will add This information to the Entry created by the server when forwarding the mail. The Entry will look like this:
Received: from SERVER1 ([xxx.xxx.xxx.xx]) by mydomain.de with ESMTPA
The trailing A after ESMTPA now tells the receiving Server, that Server1 has used a valid user account on mydomain.de to start the sending-attempt, which means that the SMTP-Server knows the origin of the mail and could provide information about the sender.
Still, the local SMTP-Server is not a known one, so in this case it might end up beeing greylisted and checked on various RBLs, which shouldn't be any problem in this case.
If the (local) SMTP-Server now passes ALL checks (Reverse-DNS Lookup, Greylisting, RBLs and what not) - the mail has a good chance to be successfully delivered, even if no remote smtp is used, because the server could be successfully authenticated as well as the sender using that server. (Otherwise no company could setup own servers)
So, using SMTP-Auth (Or any other authentication method) will also have an impact, even if no remote-SMTP Server is used.
Authenticated Mails are not a guarantee for not beeing considered as spam - but unauthenticated Mails are definitly ranked higher in the Spam-Score of common systems.
Had the same issue. I have checked the whole script 30 times. Each setting each . and , Checked and rechecked dns records dkim and spf 100 times.
Nothing worked.
I e-mailed hotmail/outlook/live about the issue. I didn't expect any help but within a few hours the problem was solved.
It wasn't in the script. Hotmail just blocks any e-mail that is sent trough most webpages. Even if your spam reputation is fine. They have placed the server's ip on a whitelist and the problem was solved.
They can change it back if they detect bad behavior. There's a limit for sending e-mail. If your server has a bad reputation they aren't likely to add the server to their whitelist. This can be an issue on shared hosting packages. Someone else on the same server where you host your website can f up the servers reputation.
Have you tested on a live server? If yes, what error did you get?
Have you enabled your phpmailer's debug to know what errors it has? If you are not using SMTP you can test with this
$mail->do_debug = true;
If you are using SMTP then use
$mail->SMTPDebug = true;
What output did you get from your debugger? You get a clue to where your problem is coming from from there.
I also suppose #dognose's answer by asking you to better use SMTP. That way your email passes through an authentication which would help indicate your identity was confirmed.
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port
$mail->Username = "yourname#yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
If $mail->Port = 26; doesn't work you can try $mail->Port = 25;.
The SPF currently being published by your DNS is invalid because you have three records!:
# dig +short txt immortalinsurance.com
"v=spf1 a mx include:smtp.secureserver.net ~all"
"v=spf1 mx mx:v=spf1 a mx include:secureserver.net ~all include:secureserver.net -all"
"\"v=spf1 a\""
The first one is valid; You should delete the second two.
The content of this record is correct for your domain if you are sending mail from 182.50.130.73. The 'mx' stanza is not strictly necessary since it points at secureserver.net anyway, but it may save DNS lookups on receiving servers.
Before you start sending email using mail() or SMTP, make sure you create valid sender email account in your cpanel.
From = "noreply#immortalinsurance.com";
This is very important if not all emails you send will be tagged as SPAM and goes to junk.
Once this is done, you must setup domainkeys and SPF records. Having a dedicated IP instead of using shared given by your hosts will also help with the delivery.
Finally check your mail with all three major email providers such as Hotmail, Yahoo and Gmail.
You will probably have to break down the exact reason why step by step. I know for a fact Hotmail is using a rules based spam filter (which is quite strict) and Gmail uses more like a self-learning system, which could explain why Gmail accepts your message and Hotmail doesn't.
The following you can check though:
A spf-record only works on the domain the spf record is added and only works for mail sent from ips/domains defined in that spf. Therefore make sure your code is executed from a server that exists in your spf.
Using SMTP as proposed above can increase derliverability (but it really depends on the receivers' spam filter). If you're testing on a local server though, you can use SMTP to send the mails trough a mail server defined in the spf. Otherwise
If the mailserver you are using is an open relay, than that could (and probably would) be a reason to add extra spam points. Thus make sure you're using a closed relay (e.g. the mailserver you're using doesn't allow mails to be sent unauthenticated users)
Check if the mailserver you're sending from isn't on any blacklist (http://mxtoolbox.com/blacklists.aspx offers a great tool);
Use the message headers in Gmail to find out if Gmail sees any reason to add spam points to your message (Howto: https://support.google.com/mail/answer/22454?hl=en). There you can find if your spf works (by searching for 'spf=pass'). This might also work for Hotmail if your mail would be delevered into the spam folder.
One of the many rules spamfilter apply are keyword checking (which I think your mail contains a few off), the amount of text and such. Make sure the overall quality of your message is good;
PHPMailer uses php's mail function by default. You can change this to sendmail ($mail->isSendmail();, probaly doesn't work on Windows if sendmail is not set up properly) or perhaps check the settings of your php.ini what mailserver is used (use ini_set('SMTP', 'yourhost.com'); to override, but this only works on Windows as far is I know).
The user of the connection data $mail->Username must be the same as the $ mail->From, otherwise hotmail rejects the email or marks it as spam.
Also, if the email has images, it can also be marked as spam.
In summary, for everything to be perfect, send email without images and that the From is the same as the Username.
I want to send mail to inbox using smtp mail method using PHP.Now mail go to spam instead of inbox,i am using smtp mail method.I had set the hostname,username and password.
<?php
define("SMTP_HOST", "mail.test.us"); //Hostname of the mail server
define("SMTP_PORT", "25"); //Port of the SMTP like to be 25, 80, 465 or 587
define("SMTP_UNAME", "tttt");
//Username for SMTP authentication any valid email created in your domain
define("SMTP_PWORD", "tttt"); //Password for SMTP authentication
?>
Mail code
//smtp mail
$mail = new PHPMailer;
$mail->Host = SMTP_HOST;
$mail->Port = SMTP_PORT;
$mail->SMTPAuth = true;
$mail->Username = SMTP_UNAME;
$mail->Password = SMTP_PWORD;
$mail->AddReplyTo("test#test.com", "zamisoft");
$mail->SetFrom("test#test.com", "zamisoft.com");
$mail->Subject = $subject;
$mail->AddAddress($to, '');
$mail->MsgHTML($message);
$send = $mail->Send();
$mail->ClearAddresses();
//smtp mail
Anybody give any solution for these issue?
Add Headers to your email
$headers='From: ann#zamisoft.com \r\n';
$headers.='Reply-To: ann#zamisoft.com\r\n';
$headers.='X-Mailer: PHP/' . phpversion().'\r\n';
$headers.= 'MIME-Version: 1.0' . "\r\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1 \r\n';
$headers.= "BCC: to";
It's been a while since I've played with PHP mail, but if that doesn't work it should put you on the right track.
Make sure you have SPF and DKIM setup. Since you are mailing from your own server, this is highly recommended.
Here is a link to Namecheap with screenshots. I couldn't explain it better:
https://www.namecheap.com/support/knowledgebase/article.aspx/9214/31/email-authentication-tool-in-cpanel-spf-records
Also, there are various checkers out there that well validate your SPF, DKIM, and check other things, and give it a score.
http://www.port25.com/support/authentication-center/email-verification/
https://www.mail-tester.com
http://dkimvalidator.com
The only things you can do when mailing from your own server. Use SPF and DKIM. Stay away from spammy words. One wrong word can make the difference of spam or inbox. Have a baseline email and baseline subject for testing. I had a slogan of mine that landed me in the spam folder, so I had to change it because I wanted it in the signature of my emails. Using certain link shorteners could land you in the spam folder. I am not saying they do, but using bit.ly or tinyurl links could land you there. Using tinypic or another image hosting service could. Your domain name could be the problem! The from name..
Remember, every word (whether it's in your email address, domain name, hostname, subject, or the body of the email) is looked at.
As well as your server's IP address. Is it on any blacklists? Check it with http://mxtoolbox.com/blacklists.aspx
Without one of us actually getting on your server and sending dozens of test email to see what is actually causing it, I can only tell you the dozens of things to check.
With all that said, mailing off your server sucks and I don't recommend it. I suggest using SendGrid or Mailgun. I had a client landing in the spam folder, on a new server, clean IP, new domain, everything. I put him on SendGrid and he wasn instantly going into the inbox.
For development, or a low level site, mailing off your server is fine if your hitting the inbox most of the time. But anyone that takes their site serious and the emails hitting the inbox is important, use a 3rd party. Most servers (from GoDaddy, Hostgator, etc.) are not for sending emails to tens of thousands of customers. They are web servers, not mailing (MX) servers, and they will tell you that it isn't their problem.
Update: I forgot to mention reverse DNS. You should have rDNS setup, and that is done by your upstream. So you would need to contact your webhost and ask them to setup "Reverse DNS" on your server.
Can you show the content of your mail? Are you trying to send HTML or text mail? Maybe the provider is on blacklist, check the sending IP address (see mail header) at a blacklist check.
I had these spam problems with Google Mail only when sending with mail() - after the change to SMTP all works properly.
I am having some problem on sending email through my company's website.
My company is using an Exchange Server for mailing.
Therefore, the email sent from my website HOST address not match the DOMAIN address and yahoo detected my mail as a spam or some mail service blocked and rejected.
Received-SPF: none (domain of xxxxx.com does not designate permitted
sender hosts)
Php Mailer return the following:
SMTP ERROR: Failed to connect to server: Connection refused (111) SMTP
connect() failed. Mailer Error: SMTP connect() failed.
i would like to prevent spam and able to send email through SMTP authentication, what can i do in this situation,? Thanks.
Run your domain through this, and fix everything that's wrong or missing. In PHPMailer, set $mail->SMTPDebug = 3;, to see why your rejections are happening, and read the other advice in the troubleshooting guide.
You have to configura SPF and DKIM at your server.
You need to configure SMTP credentials at phpmailer.
My forum has a problem with sending emails :
i have configured my mail settings as the following :
Mail Type : smtp
SMTP Host : myhost
Port : 587
Username & password : a valid email account on my domain
when i click on forget password to test sending emails i got the following message in error log:
Sender address is not valid for your login. Check your email program settings
I am pretty sure that this account is correct, and i tried to add test mail script to my host with the following code :
<?php
$mail = mail("myEmail", "wahahahahahaahahahahaa","I like spamming your inbox!!!", "From: Myself<your_email#here.com");
if(!$mail){
echo 'mail is not sent!';
} else {
echo 'mail is sent :-)';
}
?>
and it prints
mail is sent :-)
What i am missing here ?
I agree with Eggyal - it sounds like the hosted SMTP server is not allowing mail to be sent from the MAIL FROM address that you are using, with the authentication credentials that you are using.
To confirm this, and to rule-out a problem with the way that your application is trying to send the message - you might want to try sending a message through this SMTP server using a standard mail client (such as Thunderbird or Outlook), and using the same MAIL FROM address and authentication credentials that your application is using. If this fails with the same error, then you've confirmed that the hosted SMTP server is not allowing mail to be sent from the MAIL FROM address that you are using, with the authentication credentials that you are using.
Problem Solved.
I added my gmail on webmaster email, i changed it to domain email user then the problem is solved