6

I am completely new to PHP scripts and have put together the following code, but I would like the email received to show it is sent from the email field in the HTML form rather than the current "The Tranquility Zone Website [[email protected]]". Please can you advise what I should change. Many thanks.

<?
$msg .= "Name:\t $_POST[name]\n";
$msg .= "E-mail:\t $_POST[email]\n";
$msg .= "Telephone:\t $_POST[telephone]\n";
$msg .= "Subject:\t $_POST[subject]\n";
$msg .= "Message:\t $_POST[message]\n";

$to = "[email protected]";
$subject = "Website feedback message";


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

$mailheaders = "From: The Tranquility Zone Website <www.tranquilityzone.co.uk>\n";
$mailherders .= "Reply to: $_POST[sender_email]\n";


header( "Location: http://www.tranquilityzone.co.uk/thank_you.html" );

@mail ($to, $subject, $msg, $mailheaders);
?>
1
  • 6
    You should be careful messing with that. It's a good way to get your server blacklisted. If the from email server does not match the actual sending server you will look like spam. What's stopping the user from submitting something like [email protected] or [email protected]? Commented Dec 1, 2011 at 23:38

3 Answers 3

1

Change your code to this:

<?php
    $msg .= "Name:\t ".$_POST['name']."\n";
    $msg .= "E-mail:\t ".$_POST['email']."\n";
    $msg .= "Telephone:\t ".$_POST['telephone']."\n";
    $msg .= "Subject:\t ".$_POST['subject']."\n";
    $msg .= "Message:\t ".$_POST['message']."\n";

    $to = "[email protected]";
    $subject = "Website feedback message";


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

    $mailheaders = "From: ".$_POST['email']."\n";
    $mailheaders .= "Reply to: ".$_POST['email']."\n";


    header( "Location: http://www.tranquilityzone.co.uk/thank_you.html" );

    @mail ($to, $subject, $msg, $mailheaders);
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the advice and your expertise. This has really helped.
This should be used responsibly.
0
$mailheaders = "From: $_POST[sender_email]\n";
$mailheaders .= "Reply-to: $_POST[sender_email]\n";

or

$mailheaders = "From: $_POST[email]\n";

2 Comments

I assume that the form is on a web site. user1076476 is interested not in the server email rather in email address of the person who has filled the form. As I understood, Kai Qing suggests that one need not try to change "From:", rather use information from the $msg.
Yes form is on a website and I just want to send messages to myself and make them easy to reply to. The answers help. Thanks.
0

Looks like you have a mispelling in your 2nd mailheaders (mailherders) variable

Try this:

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

$mailheaders = "From: The Tranquility Zone Website <www.tranquilityzone.co.uk>\n";
$mailheaders .= "Reply-to: $_POST[sender_email]\n";

MY DISCLAIMER: I don't condone this type of activity as it looks very shady when you get emails from someone other than the true sender. And yes you could be blacklisted for this.

2 Comments

thanks for your help. This is just to send myself messages from an HTML form and make it easier to reply to the message directly to the sender, so no shady intentions.
@user1076476 good to hear :) didn't think there was any but just checking. For future reference that would have been a good thing to put into the original question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.