0

I am facing problem in receiving mail to my Gmail from a contact form on my website. Contact form is connected to a small PHP script. My website is uploaded on aws instance server and DNS on route 53.

Everything is updated in DNS (route 53) like MX records, SPF, DKIM, DMARC and everyday I got DMARC report but not receiving any mails for the contact form.

Below are the details

PHP script

<?php
$to = "info@mydomain";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: sender@example.com";

mail($to,$subject,$txt,$headers);
?>

MX records

1 ASPMX.L.GOOGLE.COM
5 ALT1.ASPMX.L.GOOGLE.COM
5 ALT2.ASPMX.L.GOOGLE.COM
10 ALT3.ASPMX.L.GOOGLE.COM
10 ALT4.ASPMX.L.GOOGLE.COM

SPF

"v=spf1 include:_spf.google.com ~all"

DKIM

The key which is provided by google

DMARC

"v=DMARC1; p=none; rua=mailto:info@mydomain"

These are the details updated on amazon DNS route 53 and still, I am not getting any mail.

Please anybody can help me with this.

  • 1
    How is the email configured to be sent? That is, is it pointing to an SMTP server, or Amazon SES< or is it trying to send the email directly from the Amazon EC2 instance? See also: [Why does Amazon EC2 limit port 25? - Stack Overflow](https://stackoverflow.com/questions/34694978/why-does-amazon-ec2-limit-port-25#:~:text=Amazon%20EC2%20imposes%20default%20sending,neither%20of%20which%20is%20throttled.) – John Rotenstein Jun 27 '20 at 05:48

2 Answers2

1

There could be a number of reasons for this:

  • By default port 25 is blocked, if you're sending mail using this port you would need to consider using another port.
  • Many mail providers will also either reject or mark as spam emails that come from the EC2 IP ranges, primarily because it is easy for someone to setup a free tier account and send spoof emails.

The suggestion would be to connect to a mail service over another port. If you do not currently have one setup for sending take at Amazons offering with SES, using port 587 from your server you could send emails via this service with neither of the top 2 conditions to stop traffic being met.

If there is a specific reason for needing to use Port 25 Amazon do have a process for getting it unblocked for you, but you'll need to provide many steps to prove you are not going to abuse it.

Chris Williams
  • 32,215
  • 4
  • 30
  • 68
  • Thanks for your reply, but I don't want to send emails I want to receive email from the contact form on my website. – user9065681 Jun 27 '20 at 08:09
  • hi @user9065681, if you are receiving an email from your contact form you will need to still ensure the following conditions are met as an email is still being sent. Ensure that the sender is an email you own (the From address) with a reply-to as the users email address. – Chris Williams Jun 27 '20 at 08:15
0

By default, AWS instances are blocked from using PHPs native mail() function. Your code is doing just that.

Nikster2014
  • 380
  • 3
  • 16
  • So what do you suggest? – user9065681 Jun 27 '20 at 08:05
  • You can use third party solutions like Sendgrid, SES, Twilio etc. I set up mine to send mail through Sendgrid. – Nikster2014 Jun 27 '20 at 19:27
  • Thanks, Nikster for your reply, but I think you not getting my problem. Actually I don't want to send an email I want to receive email from the contact form on my website to my g-suit Gmail account. For that contact form, I have created PHP script with is working fine but when I upload it on aws I am not receiving any mail to my Gmail account from that contact form – user9065681 Jun 28 '20 at 10:54
  • I don't think you are getting your own problem :) When someone fills out the contact us page on your site, your server needs to email that message to somewhere (your gmail account in this case). For that you are using PHP's mail() function which will not work on AWS . IOW, when you "receive" email into your Gmail account, your server "sent" it to you there, right? – Nikster2014 Jun 28 '20 at 16:57