Forum Home
Press F1
 
Thread ID: 63605 2005-11-16 01:20:00 PHP tickbox problem music_man (5482) Press F1
Post ID Timestamp Content User
404680 2005-11-16 01:20:00 Hi

I am having problems with this code:


<?php

$to='email@website . com';
$messageSubject='Contact from website';
$confirmationSubject='Website . com contact form confirmation';
$confirmationBody="Thank you for your message, here is a copy of the message you sent . \n\n";
$email='';
$enquiry='';
$body='';
$displayForm=true;
if ($_POST){
$confirmation=$_POST['confirmation'];
$email=stripslashes($_POST['email']);
$enquiry=stripslashes($_POST['enquiry']);
$body=stripslashes($_POST['body']);
// validate e-mail address
$valid=eregi('^([0-9a-z]+[- . _+&])*[0-9a-z]+@([-0-9a-z]+[ . ])+[a-z]{2,6}$',$email);
$crack=eregi("(\r¦\n)(to:¦from:¦cc:¦bcc:)",$body);
if ($email && $body && $valid &&!$crack){
if ( mail($to,$messageSubject,"Enquiry:" . "\t" . $enquiry . "\n\n" . "Message:" . "\n\n" . $body,'From: ' . $email . "\r\n") && ($_POST['confirmation']=="y") ) {
mail($email,$confirmationSubject,$confirmationBody . "Enquiry:" . "\t" . $enquiry . "\n\n" . "Message:" . "\n\n" . $body,'From: ' . $to . "\r\n");
}
$displayForm=false;
}
?>
<p>
Your message was successfully sent .
In addition, a copy for you was sent to your e-mail address .
Your message is shown below .
</p>
<?php
echo ' <p> ' . 'Enquiry:' . '\t' . htmlspecialchars($enquiry) . ' </p> ';
echo ' <p> ' . 'Message' . '\r\r' . htmlspecialchars($body) . ' </p> ';
}else{ // the messages could not be sent
?>
<p>
Something went wrong when the server tried to send your message .
This is usually due to a server error, and is probably not your fault .
We apologise for any inconvenience caused .
</p>
<?php

}else if ($crack){ // cracking attempt
?>
<p> <strong>
Your message contained e-mail headers within the message body .
This message has not been sent .
</strong> </p>
<?php
}else{ // form not complete
?>
<p> <strong>
Your message could not be sent .
You must include both a valid e-mail address and a message .
</strong> </p>
<?php
}
}
if ($displayForm){
?>
<div id="contactform">
<form action=" . website . com/contact . php"" target="_blank">www . website . com method="post">

<label for="email">Your e-mail address</label>
<input type="text" name="email" id="email" value="<?php echo htmlspecialchars($email);?>" size="30">
<br /><br />
<label for="enquiry">Your enquiry</label>
<select name="enquiry" id="enquiry">
<option>Product information</option>
<option>Help</option>
<option>Personal message</option>
</select>
<br /><br />

<label for="body">Your message:</label>
<textarea name="body" id="body" cols="70" rows="5"><?php
if ($_POST){echo htmlspecialchars($body); }?></textarea>
<br /><br />

<label for="confirmation">Send yourself a copy?&nbsp;&nbsp;</label><input type="checkbox" name="confirmation" id="confirmation" value="y">
<br /><br />

<input type="submit" value="Submit">
</form></div><?php
}

?>


Which is that if the checkbox is ticked then it sends a confirmation message to the person .

This bit here:


if ( mail($to,$messageSubject,"Enquiry:" . "\t" . $enquiry . "\n\n" . "Message:" . "\n\n" . $body,'From: ' . $email . "\r\n") && ($_POST['confirmation']=="y") ) {
mail($email,$confirmationSubject,$confirmationBody . "Enquiry:" . "\t" . $enquiry . "\n\n" . "Message:" . "\n\n" . $body,'From: ' . $to . "\r\n");
}
$displayForm=false;


may be the problem

Any ideas please?
music_man (5482)
1