我是网页设计界的新手,我的 HTML 电子邮件表单遇到了一些问题。我不确定问题出在 HTML 还是 PHP(或两者都有!),所以我将两者都发布。任何指针将不胜感激!
这是我的 HTML 表单:
<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>
这是我的 PHP 代码:
<?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
}
?>
有任何想法吗?