0

我是 HTML 5 尤其是 PHP 的新手,我一直在尝试向我发送一封测试电子邮件,其中包含表单中的信息。我收到一封空白电子邮件,在检查 Apache 日志时,它显示来自 PHP 表单处理程序的未定义变量。

HTML 表单:

<!DOCTYPE html>
<html lang="en">

<head>

    <link rel="stylesheet" type="text/css" href="formstyleb.css">
    <link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
    <script type="text/javascript" src="jquery-1.9.1.min.js"></script>
    <script src="jquery.validate.min.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
<form action="formemail.php" method="post" enctype="text/plain" id="contact">
   <fieldset>
     <legend>Your Contact Details:</legend>
<div>
<label for="author">Name:(Required)</label>
<input name="author" class="required name" id="author" type="text"
title="Please Enter Your Name!">
</div>

   <div>
<label for="email">Email Address:(Required)</label>
<input name="email"class="required email" id="email" type="text"
title="Please Enter a Valid email Address!">
</div>

 <div>
<label for="comment">Comment:</label>
<textarea rows="12" id="message" name="comment"></textarea> 
</div>
<div>
    <button type="submit" id="submit" value="Submit as Multipart/form-data">
        <img src="submit1.jpg" alt="Submit">
    </button>

</div>
<div>
    <button type="reset" id="reset">
        <img src="resetrs.jpg" alt="reset">
    </button>

</div>

   </fieldset>
 </form> 

 <script type="text/javascript" src="jqformval.js"></script>

 </body>

 </html>

PHP处理程序:

<?php
    ini_set('display_errors',1);
/*stops undefined index error*/
if(isset($_POST['email'],$_POST['author'],$_POST['comment'] )) {


    $email = $_POST['email'];
    $author = $_POST['author'];
    $visitor_email = $_POST['email'];
    $comment = $_POST['comment'];
    $comment = wordwrap($comment, 70);
 }
     $email_from = 'xxxx@yyyy.com';
     $email_subject = "Form Submission";
     $email_body = "Message from $author.\n".
     "The message reads:\n $comment".

    $to = "xxxx@yyyy.com";
    $headers = "From: $email_from \r\n";
    $headers .= "Reply-To: $visitor_email \r\n";
    mail($to,$email_subject,$comment,$headers);

      header( "Location: Thank You.html" );
 ?>
4

2 回答 2

1

尝试设置

$email = "";
$author = "";
$visitor_email = "";
$comment = "";

在脚本的开头。

另外我想知道您是否打算发送电子邮件,即使没有提供信息。如果是这样的话,那么

 $comment = $_POST['comment'];
 $comment = wordwrap($comment, 70);

应该移出 if.... 如果您只想在提供所有信息的情况下发送,那么您需要将其他所有内容移入 if

于 2013-06-04T19:16:01.827 回答
0

如何修复php文件的if条件..它可能有问题,尝试修复它: -

    <?php
    ini_set('display_errors',1);

if(isset($_POST['submit'])) {
// and add the name="submit" to the submit button

    $email = $_POST['email'];
    $author = $_POST['author'];
    $visitor_email = $_POST['email'];
    $comment = $_POST['comment'];
    $comment = wordwrap($comment, 70);
 }
于 2013-06-04T22:24:45.743 回答