0

I have this php mail() code on my site, which works fine.

It is an ecard system, my client can fill out the from info (name, email) and to info (name, email), etc and Mail goes straight to Inbox, on google, hotmail, yahoo, etc.

When the receiver gets the email he can use the reply button, and it gets the right info.

The problem is the From: header in my mail form, I want to change this from noreply@example.com to the receiver's info, or any other info. When I do that, the mail goes into SPAM mail.

Here is the code I'm using

<?php

$name = $_REQUEST['name'] ;
$motive = $_REQUEST['email'] ;
$name2 = $_REQUEST['name2'] ;
$email2 = $_REQUEST['email2'] ;
$message = $_REQUEST['message'] ;
$subject = $_REQUEST['subject'] ;
$message =  urldecode(stripslashes($message));

$headers = 'From:' . $name . ' John Q<noreply@example.com>' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers.= "Reply-To:" .$name. "<" . $motive. ">\n";
$headers.= "Return-Path: My Company<admin@datatopixels.com>\n";
$headers.= "X-Mailer: PHP". phpversion() ."\n";


$messagee = "
<html>
<head>
<title>Title here</title>
</head>
<body>
<center>
<br>
</center>
</body>
</html>
";


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

?>
Prix
  • 19,417
  • 15
  • 73
  • 132
chap
  • 65
  • 11
  • 1
    You cannot do that, why ? Because that does not depend on your code it depends on the domain holder for the given email you're trying impersonate as. That's exactly why there are things like reverse DNS, DKIM, SPF and other rules to identify that a given server and IP own that domain or that a given SMTP is allowed to send messages as a given email. – Prix Jun 05 '13 at 11:40
  • You don't have control over email clients. You never have guarantee that you mail won't be in spam. It depends on filter on the receiving end. – Leri Jun 05 '13 at 11:42
  • @chap:Try adding the last parameter in this string at the last line: mail($to, $subject, "My message.. ", $headers, "-f noreply@domain.com"); – SamDroid Jun 05 '13 at 11:42
  • Investigate why your e-mail message is classified as spam. Some spam filters put the reason into the mail header. Read [Some Tips for Legitimate Senders to Avoid False Positives](http://wiki.apache.org/spamassassin/AvoidingFpsForSenders). – Oswald Jun 05 '13 at 11:44
  • Try to change the mail content to more informal way. Some mail servers have some common pattern to move to SPAM. Also give an additional space in between name and email 'John Q' as '"John Q" '. For some mails it is necessary. – Pradeeshnarayan Jun 05 '13 at 11:53

1 Answers1

0

You must to add a needle headers:

Sample code :

$headers = "From: myplace@example.com\r\n";
$headers .= "Reply-To: myplace2@example.com\r\n";
$headers .= "Return-Path: myplace@example.com\r\n";
$headers .= "CC: sombodyelse@example.com\r\n";
$headers .= "BCC: hidden@example.com\r\n";

if ( mail($to,$subject,$message,$headers) ) {
   echo "The email has been sent!";
   } else {
   echo "The email has failed!";
   }
?> 

And I would suggest to read oswalds's

Community
  • 1
  • 1
Engineer
  • 5,911
  • 4
  • 31
  • 58
  • I tried your code above, but it goes to Spam, as soon as I change the "From:" with "noreply@domian.com" , it goes to Inbox. What a pain! – chap Jun 05 '13 at 12:06
  • Unfortunately, yes. I don't understand why! – chap Jun 05 '13 at 12:13
  • I tried adding the 5th parameter (-f noreply@domain.com) no luck too. as Samdroid suggested – chap Jun 05 '13 at 12:15
  • OKK...Try PHP Mailer library. Or Send mail through SMTP filter it before sending it. Also Try to give all details like FROM, return-path. – Engineer Jun 05 '13 at 12:15
  • does this mean anything to you? X-Get-Message-Sender-Via: intovps.datapixels.com: uid via acl_c_vhost_owner from authenticated_id: nobody from /only user confirmed/virtual account not confirmed – chap Jun 05 '13 at 12:38
  • That's what google show in the source email. somehow it does not get my header "Return-Path: someuser@datapixels.com" it gives me "Return-Path: " – chap Jun 05 '13 at 12:45
  • read my comment and u will understand why good mail servers will catch your emails as spam when trying to impersonate email's you don't own. – Prix Jun 05 '13 at 15:28