Question : Need to Create A Form  With 2 Actions.

I would like to create a form that has 2 actions...

1.  The results of the form are sent to my email address of choice  and
2. After the form is submitted, the person is forwarded automatically to another page.

What is the HTML code for this in its simplest iteration ?

Answer : Need to Create A Form  With 2 Actions.

Yes!

This script will create a form to receive input, then when the input is submitted it will produce a new page (line 39) and send the emails (line 44).

You can add anything you want after line 39 to give the new page the right look and feel.  You might use include() to bring in a separately styled HTML page.

You might add die() after line 52 to see how that works.

Best regards, ~Ray
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
<?php // RAY_form_to_email.php
error_reporting(E_ALL);

// SEND MAIL FROM A FORM

// A FUNCTION TO CLEAN UP THE DATA - AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    $str = stripslashes($str);
    $str = trim(preg_replace("/ +/", " ", $str));
    $str = preg_replace('/^ a-zA-Z0-9&+:?_\.\-/', '', $str);
    return $str;
}

// REQUIRED VALUES ARE PREPOPULATED - CHANGE THESE FOR YOUR WORK
$from  = "[email protected]";
$subj  = "Contact Form";

// THIS IS AN ARRAY OF RECIPIENTS
$to[]  = "[email protected]";
$to[]  = "[email protected]";
$to[]  = "[email protected]";

// IF THE DATA HAS BEEN POSTED
if (!empty($_POST['email']))
{
    // CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
    $email      = clean_string($_POST["email"]);
    $name       = clean_string($_POST["name"]);
    $telephone  = clean_string($_POST["telephone"]);

    // CONSTRUCT THE MESSAGE
    $content    = '';
    $content   .= "You have a New Query From $name \n\n";
    $content   .= "Tel No: $telephone\n";
    $content   .= "Email: $email\n";

    // SHOW THE NEW WEB PAGE
    echo "<h1>THIS IS THE ACTION PAGE</h1>";
    
    // SEND MAIL TO EACH RECIPIENT
    foreach ($to as $recipient)
    {
        if (!mail( $recipient, $subj, $content, "From: $from\r\n"))
        {
            echo "<br/>MAIL FAILED FOR $recipient";
        }
        else
        {
            echo "<br/>MAIL WORKED FOR $recipient";
        }
    }
} // END OF PHP - PUT UP THE FORM
?>
<form method="post">
<br/>Email: <input name="email" />
<br/>Phone: <input name="telephone" />
<br/>Name:  <input name="name" />
<br/><input type="submit" />
</form>
Random Solutions  
 
programming4us programming4us