Results 1 to 6 of 6

Thread: Formmail: How do I redirect to HTML page?

  1. #1
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Formmail: How do I redirect to HTML page?

    Hello,

    How can I direct users to a specific URL rather than have them see a message like "All fields are required!" or "Your email has been sent." What is the correct syntax? I made a formmail with the following PHP script:



    <?php

    // field validation
    if ($email=="" || $message=="" || $name==""|| $subject=="")

    {
    print ("All fields are required! Please go back and try again.");
    }

    else {

    // email validation
    if(!eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3})?)$', $email)) {
    print ("Your email address does not appear to be valid. Please go back and try again.");
    exit;
    }

    // send email
    $to = "info@mysite.com";
    $msg = "From: $name\n\n";
    $msg .="Email: $email\n\n";
    $msg .="Subject: $subject\n\n\n\n";
    $msg .= "$message\n\n";

    mail($to, $subject, $msg, "From: $name\nReply-To: $email\n");
    print ("Thank you $name, your email has been sent.");

    }
    ?>



    Thank you. All help will be appreciated.

    Sharez

  2. #2
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Simply by using the "header()" function. E.g.
    if ($email==NULL || $message==NULL || $name==NULL|| $subject==NULL)

    {
    header("Location: somepage.php");
    }

    else ............

    If you want a complete guide for php and mysql, a good book to buy is Julie's C. Meloni "Learn PHP, MySQL and Apache"(or something like that, I have it in a Greek version, because I'm from Greece so I don't know excactly the name in English).

  3. #3
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hope I helped.

  4. #4
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much Costas. This is exactly what I needed.



    Sharez

  5. #5
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by costas
    Simply by using the "header()" function. E.g.
    if ($email==NULL || $message==NULL || $name==NULL|| $subject==NULL)

    {
    header("Location: somepage.php");
    }

    else ............
    THat code should not be relied on as is. You need an exit statment to ensure that the content is not shown if the browser does not redirecTry this.
    PHP Code:
    if ($email==NULL || $message==NULL || $name==NULL|| $subject==NULL)

    {
    header("Location: somepage.php");
    exit;
    }

    else ............ 

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by blm126
    THat code should not be relied on as is.
    Particularly because the Location header requires an absolute URL.

    You need an exit statment to ensure that the content is not shown if the browser does not redirect.
    And if the browser doesn't redirect, a note should be included in the response containing a link to the real destination (as the HTTP/1.1 specification recommends).

    Mike

Bookmarks

Posting Permissions

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