Wednesday, 2 October 2013

php email going to the 'from' address not the to address

php email going to the 'from' address not the to address

I have been searching for a working email php script, I have everything
working except -
The email that is entered into the contact form receives the message
instead of the pre-set recipient?
I have tried all sorts of tricks to try and get this to work, the only way
I can get the mail to arrive in my web-mail account is if I type that
address into the form as the senders email.
This is the 'html' form
<html>
<body>
<form method="post" action="new-mail.php">
<div class="5grid">
<div class="row">
<div class="6u">
<input type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" name="contact" id="contact" placeholder="Email" />
</div>
</div>
<div class="row">
<div class="12u">
<input type="text" name="subject" id="subject"
placeholder="Subject" />
</div>
</div>
<div class="row">
<div class="12u">
<textarea name="message" id="message"
placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<input type="submit" class="button" value="Send Message" />
<input type="reset" class="button button-alt" value="Clear Form" />
</div>
</div>
</div>
</form>
</body>
</html>
and this is the php mailer -
<?php
$subject = $_POST['subject'];
$message = $_POST['message'];
$email = 'net@webmail.address';
$who_sent = $_POST['contact'];
$headers = 'From: ' . $who_sent . "\r\n" .
'Reply-To: ' . $who_sent . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$name = $_POST['name'];
mail($email, $subject, $message, $name, $headers);
?>
When the mail is received at the intended senders email address it list's
the recipient as being the intended send to address, and the from address
is the web host 'user@server.web-host.net'
I am finding this a little confusing, I have tried setting the form id and
name for the email field to different text, I have tried putting the
recipients address directly into the mail(), and a good many other
combinations too. For some reason it makes no difference to the outcome.
The host is 000webhost.com which is a linux based server if that makes any
difference to this.

No comments:

Post a Comment