The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 3 of 3

Thread: Email Form problems

  1. #1

    Email Form problems


    I just read the tutorial about making a PHP email form and it was great. There's just a couple of things I'd like to know how to change...

    First off, when the user hits submit, I don't want it to 'echo' a message, I'd like it to take them to another web page. I made a simpler form previously that contained this line "header('Location:thanks.html');" but when I try to include this in the new script, it doesn't work.

    Secondly, when I receive an email using this form, it includes all of the details in the body, but it doesn't populate the 'From' box with the user's email address. The previous script contained this line: "mail('', $subject, $enquiry, 'From:' . $name . ' <' . $email . '>');" but again, when I try to replace the line in this script, it displays an error.

    Here is the script I am using (I have made some minor alterations, but they all work ok). Can someone please tell me where to make the necessary changes so I can redirect users to another HTML page and also how to populate the email field in my client?

    Thanks in advance!

    if(isset($_POST['submit'])) {

    $to = "";
    $subject = "Website Query";
    $name_field = $_POST['name'];
    $phone_field = $_POST['phone'];
    $biz_field = $_POST['business'];
    $email_field = $_POST['email'];
    $message = $_POST['message'];
    $dropdown = $_POST['drop_down'];

    foreach($_POST['check'] as $value) {

    $check_msg .= "\n$value\n";


    $body = "Name: $name_field\n\n E-Mail: $email_field\n\n Phone: $phone_field\n\n Business: $biz_field\n\n Areas of Interest:\n $check_msg\n Message:\n\n $message\n\n Heard from: $dropdown";

    echo "Data has been submitted to $to!";
    mail($to, $subject, $body);

    } else {

    echo "blarg!";


  2. #2
    Updated code:

    PHP Code:
    if(isset($_POST['submit'])) {

    $to "";
    $subject "Website Query";
    $name_field $_POST['name'];
    $phone_field $_POST['phone'];
    $biz_field $_POST['business'];
    $email_field $_POST['email'];
    $message $_POST['message'];
    $dropdown $_POST['drop_down'];

    $_POST['check'] as $value) {

    $check_msg .= "\n$value\n";


    $body "Name: $name_field\n\n E-Mail: $email_field\n\n Phone: $phone_field\n\n Business: $biz_field\n\n Areas of Interest:\n $check_msg\n Message:\n\n $message\n\n Heard from: $dropdown";

    $header="From: $email_field\r\n";


    header("Location: thank-you.phtml");

    } else {


    Note: Setting the 'From' field to the email submitted in the form may result in the email not reaching the destination. For details see: Why is my PHP script not sending emails?

    More info :
    Form to email using PHP

  3. #3

    Thank you!

    That's brilliant, thank you so much! It does exactly what I want it to now!


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012