HTML电子邮件表格不能正常工作:

问题描述:

我是全新的网页设计世界,我在使用我的HTML电子邮件表格时遇到了一些麻烦。我不确定问题出在HTML还是PHP(或两者都有!),所以我发布了两个。任何指针将不胜感激!HTML电子邮件表格不能正常工作:

这里是我的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 = "*****[email protected]"; 
$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._%-][email protected][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 
} 
?> 

任何想法?

+2

a)给你的表单一个方法(例如'method =“post”')和b)发布你得到的错误。 – j08691 2013-05-03 15:53:35

+0

'method =“request”'不是有效的HTTP方法。你想'POST'。再加上,不要**用**来压制错误。 – 2013-05-03 15:55:20

尝试method="get"method="post"。这两者中的任何一个都将在PHP中填充全局$_REQUEST[]

更改此

<form name="send_form_email" method="request" action="send_form_email.php"> 

<form name="send_form_email" method="POST" action="send_form_email.php"> 

request不是为method属性的有效值。 It must be either get or post

A form element is not allowed to have a <tr> element as a child。整个表格必须包含在表格中,或者表格必须完全包含在表格单元格中。当试图从这个错误中恢复时,一些浏览器会将表格移出表格,而将输入留在后面。这使得表单和输入无用。

这两个问题会,如果你有used a validator执行你的HTML的基本QA已经凸显。