Hello..
After quite a bit of reading up and playing about i just cant seem to find an answer that will work for something which should be very easy and straight forward.
Basically i have a self-validating php form that sends the users input to my email inbox.
What i need to do on the form is add a single check box (which i have already done) which the users will just tick if they wish to receive a newsletter..
Now my problem is i just cant get my head around the code i will have to use to send this details to me. All i need to receive is a simple “yes” in the email i get if they checked the box and nothing if they didn’t…
I just don’t know how to achieve this….
Here is the code i am working with….
[code=php]<?php
$to = “[email protected]”;
if (!isset($_POST[‘submit’])) {
showForm();
} else {
$error = 0;
if(empty($_POST[‘name’])) {
$error = 1;
$errstr[] = “Please enter a name”;
}
if(!preg_match(“/^(?:[wd]+.?)+@(?:(?:[wd]-?)+.)+w{2,4}$/”, $_POST[’email’])) {
$error = 1;
$errstr[] = “Please enter a valid email address”;
}
if(empty($_POST[‘message’]) || preg_match(“/^enter your message here$/i”, $_POST[‘message’])) {
$error = 1;
$errstr[] = “Please enter a message”;
}
if(empty($_POST[‘imagetext’])) {
$error = 1;
$errstr[] = “Please validate the security code”;
} else {
include “securimage.php”;
$img = new securimage();
$valid = $img->check($_POST[‘imagetext’]);
if(!$valid) {
$error = 1;
$errstr[] = “The security code you entered was incorrect”;
}
}
if ($error == 1) {
echo “<center>n<font style=”color: #FF0000″>n”;
foreach($errstr as $err) {
echo “<li> ” . $err . “</li>n”;
}
echo “</font>n</center>n<br />nn”;
showForm();
} else {
@mail($to, “Enquiry”,”On” . date(“r”) . “, ” . $_POST[‘name’] . ” from ” . $_POST[’email’] .
” sent the following message.nEnquiry – ” .
$_POST[‘reason’] . “nn” . “nn” . stripslashes($_POST[‘message’]), “From: ” . $_POST[’email’]);
echo “<font style=”color: #003366″><left>n<b>Thank You.</b><br /><br /> Your contact form submission has now been successfully sent to us.<br /><br />One of our team will be responding to your enquiry very shortly.</font>”;
}
} //else submitted
function showForm()
{
$_POST[‘message’] = @htmlspecialchars(@$_POST[‘message’]);
echo <<<EOD
<form method=”POST”>
<table cellpadding=”5″ cellspacing=”1″ width=”90%” align=”left”>
<tr>
<td class=”style3″>Name:</td>
<td align=”left”><input type=”text” name=”name” size=”40″ value=”{$_POST[‘name’]}” /></td>
</tr>
<tr>
<td class=”style3″>Email:</td>
<td align=”left”><input type=”text” name=”email” size=”40″ value=”{$_POST[’email’]}” /></td>
</tr>
<tr>
<td class=”style3″>Enquiry:</td>
<td align=”left”><input type=”text” name=”reason” size=”40″ value=”{$_POST[‘reason’]}” /></td>
</tr>
<tr>
<td class=”style3″>Message:</td>
<td align=”left”><textarea name=”message” rows=”5″ cols=”35″>{$_POST[‘message’]}</textarea></td>
</tr>
<tr>
<td align=”right” class=”style3″><input name=”subscribe” type=”checkbox” value=”{$_POST[‘subscribe’]}” /></td>
<td align=”left” class=”style2″>Subscribe me to the news letter.</td>
</tr>
<tr>
<td align=”center” colspan=”2″><img src=”securimage_show.php” alt=”security code”></img></td>
</tr>
<tr>
<td> </td>
<td class=”style4″>(Enter above code) <input type=”text” size=”20″ name=”imagetext” /></td>
</tr>
<tr>
<td> </td>
<td class=”body” align=”left” colspan=”2″ ><input type=”submit” name=”submit” value=”Submit” /> <input name=”reset” type=”reset” id=”reset” tabindex=”5″ value=”Reset” /></td>
</tr>
</table>
</form>
EOD;
}
?>
I know this must be relatively straight forward but im afraid on this occasion i just cant seem to see the wood from the trees…
Thanks in advance for any responses this may produce.
Bolty2uk