Wordpress is not sending emails to Gmail - php

None of my Wordpress emails are sent to Gmail. More info:
I am using EXIM mail server
I am using wordpress latest version
it happens only when emails are sent to Gmail
EXIM logs say that the email is sent succesfully to Gmail, but they are not sent, or sent in spam.

The problem is a combination of factors:
EXIM, unlike postfix, is not automatically setting the Sender header
Gmail recently made some changes to deal with spam better, and if the email headers are missing the Sender header, it will most likely silently discard it, or send it as spam.
Wordpress doesn't set the Sender header
Once you know these, the fix is quite simple. If you are using Wordpress, the quick and dirty way to do it is to go to wp-includes/pluggable.php, look for the wp_mail() function search for:
$phpmailer->From = apply_filters( 'wp_mail_from' , $from_email );
then add the following right after it:
$phpmailer->Sender = $phpmailer->From;
Once you do this, emails will work, and you can fix the problem the proper way, without overwriting the core, by writing a plugin. Wordpress uses phpmailer which knows about this issue, but wordpress doesn't use it. There is also a bug report on this issue.
To fix the problem using the core mail() function, you have to do the following:
// $sender can be the same email address as the From header
mail($to, $subject, $message, $additional_headers, "-f {$sender}")
There is another option that may work, depending on the configuration of your server (I couldn't test it, would love if someone could test this):
$sendmailFrom = ini_get('sendmail_path');
ini_set('sendmail_path', $sendmailFrom . ' -f sender#mysite.com'); // or whatever you want

Gmail (and likely Hotmail and Yahoo eventually) is starting to disable traditional SMTP authentication mechanisms (PLAIN, LOGIN and CRAMMD5) in favour of OAUTH2.
If you send mail with WordPress (PHPMailer) alone, Gmail will discard it or mark it as SPAM. If you send mail with a typical WordPress SMTP plugin, Gmail will give you an authentication error, or make you jump through hoops like application-specific passwords, two-factor authentication, and enabling less secure apps as an account setting.
The first plugin to implement OAuth 2.0 for WordPress (disclaimer, I am the author) is Postman SMTP. If port TCP 465 allows outbound connections to Gmail, your WordPress emails will be delivered by Postman without error.

Related

Using phpmailer with SMTP for my web application

I am building a website with PHP for a client. The website has a contact form, so I added the phpmailer class to be able to send the contact form details to the client's mail address.
Now, when I configure the phpmailer class, I have to provide the SMTP server username and password (I used smtp.gmail.com). I highly doubt that my client will give me his gmail credentials.
When I use the phpmailer class without enabling SMTP configuration (i.e not giving $mail->isSMTP() and the relevant configurations that follows it), I get the message marked as SPAM in my inbox. I can't use the php mail function because I want to format the body of the email as a template with HTML and CSS.
Is there a way I can use the phpmailer class(no SMTP) without getting the email marked as SPAM? or Is there any other solution for the problem I am facing?
Emails sent by phpmailer being marked as SPAM is a much more complex issue. You might find a good explanation:
phpMailer gmail spam
Even the GitHub of PHP Mailer also has this discussion:
https://github.com/PHPMailer/PHPMailer/issues/111
There are also quite a few search results on Google, regarding this topic.

Laravel 4 Mail - failed SMTP on server, switching to mail method

This is quite strange as email sending using my Gmail SMTP server works in my localhost, but when I deployed it on a VPS, it wouldn't work at all.
I can't find any issue as to why this is happening, the configuration looks normal (SSL port 465, Gmail SMTP server). I'm using Laravel 4.0.9 so I thought of upgrading to 4.1/4.2 to use the Mailgun feature (not sure if 4.0 can use Mailgun?)
Anyway, for a quick fix, I just switched to mail method for email sending. Since this works well for me, my question is that whether there is any tradeoff of using mail instead of SMTP on Laravel? The delivery seems okay as it got to my inbox, but what about the long term?
Any thoughts would be very much appreciated :)
When using the built-in mail function you don't benefit from additional features such as DKIM and the SFP configuration for your domain may not allow hosts other than your SMTP mail server to send mail for your domain, all of this makes the mail you send that way look like spam to other servers.
While you may not have issues with some providers, try to send mail to some more restrictive providers such as Outlook (ex-Hotmail); I'm pretty sure all the mail you send there will be automatically marked as spam because of the issues described above.
PHP mail may be faster since you don't have to connect to your smtp server, but it's not better. In the long run, SMTP email is the only way to guarantee that your email will arrive in the inbox of your receivers

php sendmail() from same domain - is it considered SPAM now?

I want to know if using PHPmailer functions to send HTML or plain emails
would be not considered as SPAM by mail servers if it would originate
from the domain with the same name.
For example :
sending email with PHPmailer as "info#mydomain.com"
originating from "mydomain.com" domain (as opposed to say GMail server or other mail servers).
I have a "password lost" system that sends emails to people using my website/portal
and so far i tested the function with my GMail account. I wonder that when I will move
to new hosting, linux box, and configure the domain on that box, and add a mail account and use PHPMailer locally, with that mail account, maybe it would be totally cleaner and will not go in SPAM folders when I sent mails.
Let me know your thoughts about it,
and if this really works
thanks,
Your mails originating from yourdomain.com sent as info#yourdomain.com will not be marked with "using domain yoursharedhostingdomain.com" in gmail, so mails shouldn`t drop in the spam folder for that reason.
With Gmail here i mean e-mail client, not using gmail account as a sender.

Codeigniter emails not being received by gmail

I have an app where i'm sending emails on certain events, but when i used my gmail account, i never receive the emails and they are not in my spam folder. When i send them to my work email, i receive them instantaneously.
What do i need to do to get the emails through to google?
I'm using the standard codeigniter email configs (which i think uses sendmail).
I'm using google apps for business and i have the MX records setup that google provides.
Do i need anything else? Also, i'm using subdomains in my app, does that affect what i may need to setup?
EDIT
When i use smtp like this example Sending email with gmail smtp with codeigniter email library, the page never seems to come back. It eventually just timesout.
The only plausible explanation for this behaviour is a SPF Check failure. SPF or Sender Policy Framework is a new technology that allows easy detection of spam. Gmail honours SPF unless you manually mark those emails as not spam. Regardless of this, if you have received emails on another address then they must have reached Gmail too. Check your spam thoroughly, as Gmail does not discard emails even on very high spam suspicion rather they end up in the Spam folder.
You can set up a SPF that allows your webserver to send emails which will result in Gmail accepting emails sent by your webserver as authentic. See http://www.mydigitallife.info/how-to-set-up-and-create-sender-policy-framework-spf-domain-dns-txt-record-with-wizard/ and a wizard from Microsoft.
You will probably see, that at some point in the future, you'll get them all appearing in Gmail. Google is most likely seeing if the sender is spam, and holding those messages. I've experienced that before setting up dev servers. I would suggest using a transactional email service, like Mandrill or SendGrid. You'll find you get a lot of info from those services that you forgo if you simply send an email through PHP.
The Filter Theory The other possibility is that the poster has a filter set up on their GMail account that is filtering out the emails.
I would make sure that you are sending the required header information as well. Have you tried registering a new gmail account and sending it to that user?

PHPMailer issue

I'm using PHPMailer for sending activation codes to users. As far as I know, that's best script for this purpose. Today noticed that, some users doesn't receive activation codes. But mailer return "Succesfully sent" message. Is there any chance that, phpmailer can't send to some mail servers? Or which is the best php script for sending mail via smtp authentification in your opinion?
It's not obvious that it is PHPMailer problem. It has connected to your smtp server and successfully sent the message. By successfully I mean that your server has accepted it. What happens next is a mystery and you have no control over it.
Few common reasons of undelivered mail:
marked as SPAM by foreign server (advise users to check their spam folder)
target mailbox does not exist (typos in username etc)
user inbox is full and will not accept new mail
mail queue on the server is quite big and it will take few minutes / hours to deliver
The best you can do is to advise users to keep their mailboxes clean, check their spam folder, retype email to prevent typos and offer a service for re-sending the activation email.
I send registration and activation emails using SwiftMailer via Google Apps Mail (support#mydomain.com). It works like a charm, easy to setup, and has no delivery issues since it's using Google's servers. Check it out.

Categories