Question

My code is this:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$messagesubject = $_POST['subject'];
$text = $_POST['text'];

$to = "name@email.com";
$subject = 'Message from a site visitor '.$name;

$content = 'Name: '.$name."\r\n";
$content .= 'E-mail: '.$email."\r\n";
$content .= 'Subject: '.$messagesubject."\r\n";
$content .= 'Message: '.$text."\r\n";

$headers .= 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
"; 

$send_contact=mail($to,$subject,$headers,$content);

if($send_contact){
echo "Thank you!";
}
else {
echo "ERROR";
}
?>

I receive a mail but on the senders address (From) is written my e-mail address from the hosting server. If i add $headers ( i created the headers like this: $headers = 'From: '.$field_email."\r\n"; ") in the mail() than i don't receive any mail...

what do i do wrong? Im a begginer in this

Was it helpful?

Solution

Well, as manual says ( http://php.net/manual/en/function.mail.php ) mail function variables go like this:

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

and Your looks like that:

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

switch it and You should get what You want :)

OTHER TIPS

A valid From: header in an email must contain a valid email address:

From: <someone@somewhere.xxx>

Note the encloseing brackets. You may also add additional text:

From: Someone Important <someone@somewhere.xxx>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top