Question : Simple PHP Form Validation and Email forwarding

Hi Experts, I'm pretty sure this will be an easy one, but here goes.

1)  In my PHP code please see the if statement below the comment "//validation". What I want to do is add a few more variables like "name" ,"phone"  along with "company" into this particular statement, I just can seem to get the syntax right.

2) In the if statement just below the comment //email , I would like to include the email address that was captured in the SQL statement so that folks who out the form get an email response with the same results.. ANy ideas on how I could do this?  

Many thanks,

Scott

Code Snippet:
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:
 $val)
{
    $key = str_replace('_', ' ', $key);
    $message .= $key .' '. $val . $crlf;
 
}
 
mail($to, $subject, $message);
 
// confirm
if ($_POST['SQL_query_result'] = 'ok')
{
      mysql_close($con);
header('Location: thanks.html');
exit;
}
else
{
	die('Error: ' . mysql_error());
}
Open in New Window Select All

Answer : Simple PHP Form Validation and Email forwarding

Ah, I see. For the validation you simply need to use the 'or' operator to check if any of the require fields are blank (see snippet).

As for the email, I think (though it's a little while since i used mail) that you can just separate email addresses by commas. Try the snippet below.

Rich
1:
2:
3:
4:
5:
6:
7:
8:
//validation
if ((!$_POST['company'])||(!$_POST['name']) ||(!$_POST['email']))
{
die('You did not submit all required fields');
}
 
//mail
$to = $_POST['email'].", [email protected]";
Open in New Window Select All
Random Solutions  
 
programming4us programming4us