Florin Pop
Florin Pop

Reputation: 5135

Php email function not working properly

I know this seems like it is a duplicate but please read first:

I have the following php code:

<?php

$to = '[email protected]';

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$headers = "From: ".$email." \r\n";
$headers .= "Reply-To: ".$email."\r\n";

mail($to, $subject, $message, $headers); 

?> 

I think it's the standard email sending script. However, I face an interesting bug. My website is florin-pop.com and the emails are only sending when in the email input field I put something like this: [email protected] or [email protected] or anything before @florin-pop.com.

If I try to put a something different like [email protected] or even a real yahoo email address I don't get the email. Why? It's something wrong with my code? It may be from the hosting company? ( I use hostgator ).

EDIT:

If I change the Reply-To to the domains email address then it is working, but it is still not the perfect way to do it. If you press the reply button and forget about this trick, you will email yourself.

Code:

<?php

$to = '[email protected]';
$my_domain_email = '[email protected]';

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$headers = "From: ".$email." \r\n";
$headers .= "Reply-To: ".$my_domain_email."\r\n";

mail($to, $subject, $message, $headers); 

?> 

Upvotes: 0

Views: 91

Answers (1)

showdev
showdev

Reputation: 29168

In this case, delivery failure may be caused by Yahoo's adoption of the Domain-based Message Authentication, Reporting, and Conformance (DMARC) policy.

This means all DMARC compliant mail receivers (including Yahoo, Hotmail, and Gmail) are now bouncing emails sent as "@yahoo.com" addresses that aren't sent through Yahoo servers. [Yahoo]

Twitter, Facebook, Linked In, Paypal, AOL, Comcast and others have also adopted this policy. [Venture Beat]

A solution: Change the "From" header to an address at the server from which you are sending the email. This (correctly) indicates that the mail was sent from your server, and not from Yahoo. You can still use a user-submitted address in the "Reply-To" header so that the recipient can reply to the sender.

As a best practice, you should ... be using a domain you control in ... the "From:" header... [For example,] the site visitor's name is shown in the descriptive part of the "From:" header, and the "Reply-To:" header is set to the website visitor's address, but the actual address used in the "From:" header clearly indicates that your website is the origin of the message. [DMARC]

Upvotes: 1

Related Questions