Jump to content

Emails marked as spam by Gmail


alexpi
 Share

Recommended Posts

Hello,

I have a Processwire site that was made some years ago, and I got a complaint that the emails originating from it, ended up in Gmail's spam folder. I updated Processwire to 2.8, and changed the PHP mail() function I used before, to the newer $mail helper. In the beginning I used a Gmail email for the recipient, but later changed to an info@site.com type, thinking that this could be the problem. Still, the emails are marked as spam.

I used the following code (simplified):
 

$name = $input->post['name'];
$emailFrom = $input->post['email'];
$message = $input->post['message'];

$form = array(
    'name' => $sanitizer->text($name),
    'email' => $sanitizer->email($emailFrom),
    'message' => $sanitizer->textarea($message),
);

$message = "Name: $form[name]\n" . 
         "Email: $form[email]\n" . 
         "Message: $form[message]";
                 
$email = $mail->new();
$email->subject("Subject")
    ->to($pages->get('/settings/')->main_email)
    ->from($form['email'])
    ->body($message);

$email->send();

Should I use email header parameters? I can't find what to do in the docs.

Thanks

Link to comment
Share on other sites

For a complete documentations of $mail take a look here: https://processwire.com/api/ref/wire-mail/

8 minutes ago, alexpi said:

, and changed the PHP mail() function I used before, to the newer $mail helper.

$mail does also use mail() internally if you don't use any 3rd party WireMail module. I'd suggest you to install one of them to not send your emails from php directly. If you still get spam flags then you should look into email domain verifications like SPF or DKIM and maybe use one of those email testing services to analyse your sent mails for other spam triggers.

  • Like 4
Link to comment
Share on other sites

I used the WireMailSMPT module, signed up to an SMTP service (Mailjet), got SPF and DKIM authentications but the service prompts me to validate every email I receive!

I am not sure if I am using $mail correctly, the docs are a little sparse. Do I need to add additional headers or something else?

 

Link to comment
Share on other sites

$m = $mail->new();
$m->from('noreply@yourdomain.com');
$m->to('alexpi@yourdomain.com');
$m->header('Reply-To', $emailBackTo);
$m->send();

Like I said in the WireMailSMTP modules topic: If you use such a service do not send emails with a "From" address, which is not your own. 

Link to comment
Share on other sites

5 minutes ago, LostKobrakai said:

$m = $mail->new();
$m->from('noreply@yourdomain.com');
$m->to('alexpi@yourdomain.com');
$m->header('Reply-To', $emailBackTo);
$m->send();

Like I said in the WireMailSMTP modules topic: If you use such a service do not send emails with a "From" address, which is not your own. 

Thanks LostKobrakai, It makes sense now, and it works as expected!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...