I've been trying to get the mail() function of PHP to work by posting JSON to a response.php which handles the actual sending. After numerous attempts I still fail to get the message to the receiver. The problem I'm getting now is that the message needs to be RFC 5322 compliant:
wouter0.7@live.nl
host mx2.hotmail.com [65.54.188.72]
SMTP error from remote mail server after end of data:
550 5.7.0 (BAY004-MC1F14) Message could not be delivered. Please ensure the message is RFC 5322 compliant.
Message output of the script is:
asdada\r\n\nName: Www\r\nEmail: wouter0.7@live.nl
(Keep in mind that I just hit a few buttons after a thousand times of trying, so the message is not making sense.) I've used the example on PHP Manual:MAIL() to create the headers, so they look like this:
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
When I look in the message I got from the mail delivery system, the headers seem to order. The message, however, seems to get messed up in the process, causing the mail delivery to fail.
Does anyone know why this could occur? Please let me know if I need to upload more code/examples.
EDIT: Forgot to mention that I already tried adding a fifth parameter to the mail() function:
mail($to,$subject,$message,$headers,"-f your@email.here");
as suggested here EDIT 2: Code that I use for the mail() function:
//Send Mail
$to = "wouter0.7@live.nl"; // Your email here
$path = $_SERVER['HTTP_HOST'];
$subject = 'Message from ' . $path; // Subject message here
$email = $return["email"];
//Set headers
$headers = 'From: ' . $email .''. '\r\n'.
'Reply-To: '.$email.'' . '\r\n' .
'X-Mailer: PHP/' . phpversion();
$message = $return['msg'] . '\r\n\n' .'Name: '.$return['name']. '\r\n'
.'Email: '.$return['email'];
mail($to, $subject, $message, $headers,"-f wouter0.7@live.nl");
the $return array is used to encode to JSON, it just contains string-values