Jump to content

[Solved] php mail() not getting to gmail


Recommended Posts

I'm trying to get php mail() working with gmail. It sends the message to my domain fine however it isn't received if I change it to my gmail address. I did try PHPMail but read here that uses mail(), so that didn't work either. Does anyone know a way around it? Thanks

	<?php
	echo "About to send test email...<br />";
	$to = "XXXXXX@gmail.com";
	$subject = "Test Mail";
	$message = "Hello world!";
	$headers = "From: YYYYYYY.helioho.st";
	$success = mail($to, $subject, $message, $headers);
	if ($success) {
		echo "Mail sent successfully...<br />";
	} else {
		echo "*** Mail could not be sent...<br />";
	}
	?> 

 

Link to comment
Share on other sites

Have you tried a test email with more realistic content, and not things like "test email / hello world"? I noticed during some of my own email testing that Gmail's filters will prevent things like that from even being put into the spam folder, they just go into a black hole. But when my test emails contained a quick pretend update about groceries needed or making dinner plans, I had better success at getting my messages received to my Gmail account.

Link to comment
Share on other sites

Gmail does not accept email from us by default because SPF and DKIM are not set up unless you request it (or you can set them up yourself if you're using external DNS). If you send mail from a mailbox in Plesk's webmail, you'll get a message back from Google explaining this.

For automated emails such as from mail() it will report a success yet never arrive. There's no mailbox on the sending end, so your email gets sent, Google throws it out, and you can't receive the error back. PHP will report a success since mail() returns true when the send succeeds, not when it delivers, ...PHP doesn't care about, and has no way of knowing, that the receiving end discarded what it sent.

The fix for this is usually to set a From address in the mail command (e.g. set the header paramater to "From: noreply@marckeeley.helioho.st"), then request that SPF and DKIM be set up for marckeeley.helioho.st. 

Do you want me to get SPF and DKIM set up for your domain?

Link to comment
Share on other sites

DKIM, SPF, and DMARC have been set up for the domain marckeeley.helioho.st. We recommend sending a test email to https://www.mail-tester.com/ to make sure that everything is set up correctly. If you get less than a 10/10 score please post a link to the full report so we can help you fix any other issues that there may be.

  • Thanks 1
Link to comment
Share on other sites

  • Krydos changed the title to [Solved] php mail() not getting to gmail
  • Krydos locked this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...