4

I am trying to send a google login link in email body, but it always marks as spam.

The reason which i've found only is accounts.google.com, even though the 'google.com' also not. When i put account. in start of this; it goes to spam otherwise everything works perfect.

See the link and email body below.

$google_link='accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri='.$site_url.'&client_id='.$client_id.'&scope=email+profile&access_type=online&approval_prompt=auto'; 

 $html.='<div>

         <a href="'.$google_link.'">Click here</a>

    </div>  
            ';

wp_mail( $email_address,subject, $html, $headers);

Question: Is there any way to encrypt this URL in email body to send and it works proper in email/gmail inbox?

Is there any other way to avoid the email going to spam like marking specific email by it's subject using any third party mail sending tool?

Esar-ul-haq Qasmi
  • 1,052
  • 1
  • 14
  • 30
  • UnSpam your email. Teach your spam filter, that it's not spam – Justinas Sep 22 '17 at 10:53
  • Your URL is not an absolute URL. Add `https://`to the beginning of your URL. Also provide a text mime only version of your email too. Then again use a full HTML markup. I'm not sure if wp_mail handles that for you – lumio Sep 22 '17 at 10:53
  • @lumio yes i am using text mime type already `$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; ` and the URLs is kind of absolute, the above code is just an example, i am adding `https://` dynamically through some simple logic, in short the url becomes the absolute before sending email. – Esar-ul-haq Qasmi Sep 22 '17 at 11:05
  • That is a html mime type. I meant `text/plain` - should have made it more clear :) - Maybe [this article (Reach More People and Improve Your Spam Score: Why Multi-Part Email is Important)](https://litmus.com/blog/reach-more-people-and-improve-your-spam-score-why-multi-part-email-is-important) would help too – lumio Sep 22 '17 at 11:07
  • @lumio i've applied your suggestion `text/plain`, it doesn't work and the email body templates went off due to this. – Esar-ul-haq Qasmi Sep 22 '17 at 11:10

1 Answers1

0

You can use the third party service SendGrid by registering and installing their WordPress plugin. SendGrid process your email text and replace links with links to SendGrid such that the accounts.google.com will not appear in the email. Upon a user clicking the link, SendGrid will record the click and redirect to your original URL.

Alternatively you could create your own redirect URL. The most secure method would be to have a table to store the URLs and generate a unique token such that you could put your own link in the emails along with the token. When your script is hit, pull the target URL from the table that matches the token and redirect to it.

MrCode
  • 63,975
  • 10
  • 90
  • 112