Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 3 of 3

Thread: Email Form problems

  1. #1

    Email Form problems

    Hi,

    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('info@olicorse.com', $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!

    <?php
    if(isset($_POST['submit'])) {


    $to = "info@olicorse.com";
    $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:
    <?php
    if(isset($_POST['submit'])) {


    $to "info@olicorse.com";
    $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";

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

    mail($to$subject$body,$header);

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

    } else {

    echo 
    "blarg!";

    }
    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!

    Cheers

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 kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012