Hello,
I found this code here below and arranged it to my page requirements.
All is fine, but not the phone number field.
Oh it appears on the page alright, but I cannot manage to have the value (if entered) sent by email.
I would like to have it as optional, if noone fills it in, no error.
And if it is filled in (or not doesn't matter), I would like to see it in the email as "phone of the person: ....."
I tried so many things, but none work. Who can help me?? 😕
It is all in one htm page.
I can't wait to understand what I am missing to make it work!!
Thank you in advance,
Cath.
<html>
<head>
<title>Contact form</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<h2>Contact form</h2>
<?php
// on the initial load of the page, there is no submit hence
// the html is outputted to the page
if(!isset($_POST['submit']))
{
?>
<h3>Please contact us at <a href="mailto:my@email.com"><font color="#008000">my@email.com</font></a><br>
You can also fill in this form and click on the 'send' button. <br /><br />
</h3>
<form action=" <?php echo $_SERVER['PHP_SELF'] ?> " method="post">
<h3>
Your name <br /><input type="text" name="username" /><br /><br />
Your email address <br /><input type="text" name="useremail" /><br /><br />
Your phone number if needed <br /><input type="text" name="userphone" /><br /><br />
type of request?<br />
<select name="ftype">
<option />(select one)
<option />General inquiry
<option />Offer - Price request
<option />Cooking Workshop
</select><br /><br />
Describe your request in as much detail as possible: <br>
date of event, number of persons, how many dishes, location, <br>
preferred contact (phone or email), time of day.<br />
<textarea name="problem" rows="15" cols="60"></textarea><br /><br />
<b>Make sure your details are correct before submitting the form</b><br /><br />
<input type="reset" value="Reset">
<input type="submit" name="submit" value="SEND">
</h3>
</form>
<?php
}
// submit button has been hit, so output the final message
else
{
// first we will check to see if the input is valid
if(!isset($POST['username']) || strlen($POST['username']) <= 0)
{
echo 'Error: You did not enter your name.<br />';
exit();
}
if(!isset($POST['useremail']) || strlen($POST['useremail']) <= 0)
{
echo 'Error: You did not enter your email address.<br />';
exit();
}
if(!isset($POST['problem']) || strlen($POST['problem']) <= 0)
{
echo 'Error: You did not describe your request.<br />';
exit();
}
/* check which type of feedback was selected and take appropriate action
if($_POST['ftype'] == "General inquiry")
{
$sendto = "my@email.com";
$ftype = $_POST['ftype'];
$username = $_POST['username'];
$useremail = $_POST['useremail'];
$problem = $_POST['problem'];
mail( "$sendto", "My From: $ftype",
"name of person: $username\n\n$problem",
"phone of person: $userphone\n\n$problem",
"From: $useremail" );
}
else if($_POST['ftype'] == "Offer - Price request")
{
$sendto = "my@email.com";
$ftype = $_POST['ftype'];
$username = $_POST['username'];
$useremail = $_POST['useremail'];
$problem = $_POST['problem'];
mail( "$sendto", "My Form: $ftype",
"name of person: $username\n\n$problem",
"From: $useremail" );
}
else if($_POST['ftype'] == "Cooking Workshop")
{
$sendto = "my@email.com";
$ftype = $_POST['ftype'];
$username = $_POST['username'];
$useremail = $_POST['useremail'];
$problem = $_POST['problem'];
mail( "$sendto", "My Form: $ftype",
"name of person: $username\n\n$problem",
"From: $useremail" );
}
else
{
echo 'Error: No type of request was selected<br />';
exit();
}
?>
<h3>Thank you for contacting us!</h3>
<?php
}
?>
</body>
</html>