cjoel
By:
cjoel

How do I get my php contact form to work with Gsuite?

August 3, 2017 681 views
PHP Apache Email CentOS

I am using Gsuite for email on my VPS. It is configured properly and works for sending and receiving emails except when I use the PHP form (again, setup properly). The functionality of the form itself works so I'm certain it's something to do with the mail servers. The form submission emails aren't being sent at all, not to any email address I use. How can I get this working? I know it has to do with PHP/mail servers/Gsuite but I don't know beyond that.

7 Answers

Hi @cjoel

Without seeing any error logs, then it's difficult to tell what's going on, but a lot of new DigitalOcean accounts has SMTP blocked to prevent them from being used as spammers.
Run this command to check if you're being blocked from reaching Google's SMTP:

telnet aspmx.l.google.com 25

If you cannot connect, then you need to create a ticket with Support in the control panel and ask to un-block SMTP.

Here is what the error logs say: http://i.imgur.com/OKYwpi9.png

  • @cjoel

    I don't know what this image is. Which mail server are you running, if any?
    So you're not using the G Suite SMTP (or SMTP-Relay) servers?
    And the bottom error states that you need to add authentication when sending mail.

I'm using the G Suite via MX entries and Exim mail server is that is what you mean?

Thank you for the help, but I'm still not quite there with getting everything to work, I have the SMTP relay working now (no longer getting an error about that) but I'm still getting this error when submitting my PHP form email: (referring to the email address chosen to receive the email for the form) "The account or domain may not exist, they may be blacklisted, or missing the proper dns entries."

  • @cjoel Please click Reply link or use @ to notify people.

    Without an error log and knowing which SMTP server your PHP script is using, then it's difficult to help.
    You can usually find your mail log here:

    /var/log/mail.log
    

    But the error log of your PHP script depends on how you've coded it or which framework you're using.

@hansen Here are some logs from EXIM:

"2017-08-04 14:19:11 1ddjzz-0004rm-II ** mail@example.com root@test.example.com R=failremotedomains: The mail server could not deliver mail to mail@example.com. The account or domain may not exist, they may be blacklisted, or missing the proper dns entries.
2017-08-04 14:19:11 cwd=/var/spool/exim 7 args: /usr/sbin/exim -t -oem -oi -f <> -E1ddjzz-0004rm-II
2017-08-04 14:19:11 1ddjzz-0004rr-O3 <= <> R=1ddjzz-0004rm-II U=mailnull P=local S=5559 T="Mail delivery failed: returning message to sender" for root@test.example.com
2017-08-04 14:19:11 cwd=/var/spool/exim 3 args: /usr/sbin/exim -Mc 1ddjzz-0004rr-O3
2017-08-04 14:19:11 1ddjzz-0004rm-II Completed"

  • @cjoel

    Okay, since I don't know where you're sending mails from or to, then I have to go by the error The account or domain may not exist, they may be blacklisted, or missing the proper dns entries.
    So you need to make sure that you're sending to an address, where both user and domain exists and DNS is properly setup. Make sure you're not being blocked. And make sure your domain DNS is properly configured, since many hosts now require DNS PTR records to match in order to prevent spam.

    But it doesn't seem like you're relaying your mails through G Suite.

    So do you want to run Exim as a relay, or remove Exim and just send mails directly from PHP with a framework via G Suite?

@hansen I want to use Exim if it will work properly on my server, but I'm open to sending directly from PHP with a framework via G Suite if you think that is better. I have tested my DNS pretty thoroughly and I haven't found any problems with it which makes me think it's my mail server relay. I would also like to add that I am using Cpanel/WHM on my server running CentOS 7

@hansen I have followed both of those tutorials and haven't been able to fix the problem. I need to use Cpanel/WHM for my needs and the default mail server is EXIM, disabling it may cause problems so I would like to stick with it if I can..

Have another answer? Share your knowledge.