I'n brand-new to the web design world, and I'm having some trouble with my HTML email form. I'm uncertain whether the problem is in the HTML or the PHP (or both!), So I'm posting both. Any pointers will be greatly appreciated!
Here's my HTML form:
<form name="send_form_email" method="request"
action="send_form_email.php">
<tr>
<td width="375px" height="25px" style="text-align:right;background-color:#98CE32;"> Nom: <input type="text"
name="nom" autofocus></td>
<td rowspan="3" width="375px" height="75px" style="text-align:center;font-size:25px; background-color:#98CE32;">819.352.4711</td>
</tr>
<tr>
<td width="375px" height="25px" style="text-align:right;background-color:#98CE32;"> Téléphone: <input type="text"
name="telephone"></td>
</tr>
<tr>
<td width="375px" height="25px" style="text-align:right;background-color:#98CE32;"> Courriel: <input type="text"
name="courriel"></td>
</tr>
<tr>
<td width="375px" height="225px" align="right" style="background-color:#98CE32;"><textarea name="message" cols="45" rows="14" placeholder="Questions? Commentaires?"></textarea></td>
<td width="375px" height="225px" align="left" style="background-color:#98CE32;"><img src="excavation_rd.jpg" alt="excavationrd"></td>
</tr>
<tr>
<td width="375px" height="25px" align="center" style="background-color:#98CE32;"><input type="submit" value="Envoyer" name="Envoyer">
<input type="reset" value="Effacer" name="Effacer"></form></td>
And here's my PHP code:
<?php
if(isset($_REQUEST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "*****s@yahoo.ca";
$email_subject = "Nouveau Message de www.*****.com";
function died($error) {
// your error code can go here
echo "Nous sommes désolés, mais il y a des erreurs dans le formulaire envoyé. ";
echo "Voici les erreurs.<br /><br />";
echo $error."<br /><br />";
echo "SVP corrigez ces erreurs.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_REQUEST['nom']) ||
!isset($_REQUEST['telephone']) ||
!isset($_REQUEST['courriel']) ||
!isset($_REQUEST['message'])) {
died('Désolé, mais il y a une erreur!.');
}
$first_name = $_REQUEST['nom']; // required
$telephone = $_REQUEST['telephone']; // required
$email_from = $_REQUEST['courriel']; // not required
$comments = $_REQUEST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'Le courriel que vous avez fourni ne semble pas être valide.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'Le nom que vous avez entré ne semble pas être valide.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'Votre message ne semble pas être valide.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Détails ci-bas.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "nom: ".clean_string($first_name)."\n";
$email_message .= "telephone: ".clean_string($email_from)."\n";
$email_message .= "courriel: ".clean_string($telephone)."\n";
$email_message .= "message: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
Merci de nous avoir contacté! Nous vous répondrons sous-peu!
<?php
}
?>
Any ideas?