PHP邮件脚本给我语法错误

时间:2014-11-14 18:38:19

标签: php forms email

我试图将我的php邮件嵌入我的html页面,我在Dreamweaver中没有语法错误,但sendmail(http://glob.com.au/sendmail/)一直给我这个错误信息"参数中的语法错误 "我希望你能帮我解决这个问题

我的PHP邮件:     

//Email information
$admin_email = "------------ Secret";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];

//send email
mail($admin_email, "$subject", $comment, "From:" . $email);

//Email response
echo "Thank you for contacting us!";
}

//if "email" variable is not filled out, display the form
else  {
?>

以下是相关的网页代码

<?php
//if "email" variable is filled out, send email
  if (isset($_REQUEST['email']))  {

  //Email information
  $admin_email = "schlichtingr@yahoo.com";
  $email = $_REQUEST['email'];
  $subject = $_REQUEST['subject'];
  $comment = $_REQUEST['comment'];

  //send email
  mail($admin_email, "$subject", $comment, "From:" . $email);

  //Email response
  echo "Thank you for contacting us!";
  }

  //if "email" variable is not filled out, display the form
  else  {
?>
<html>
<head>
</head>
<body>
  <div id ="Email">         
    <form method="post"><br />
      <h3><b>send us a message</b></h3>
      <span>Any further questions or concerns? Send us an email!</span><br>
         Email: <input name="email" type="text" /><br />
         Subject: <input name="subject" type="text" /><br />
         Message:<br />
          <textarea name="comment" rows="15" cols="40"></textarea><br />
      <input type="submit" value="Submit" />
    </form>
  </div>
<?php
  }
?>

您可以给予我任何帮助,我将不胜感激 我是php新手,但仍在努力学习

基本上我只是想在html页面上构建一个邮件表单

2 个答案:

答案 0 :(得分:2)

我不熟悉sendmail,但我注意到一件事:

  1. "$subject"必须只是$subject。您正在捕获该变量是有原因的。所以把它变成一串&#34; $ subject&#34;对我来说毫无意义。
  2. 希望这有帮助!

答案 1 :(得分:1)

试试这段代码:

   //if "email" variable is filled out, send email
    if (isset($_REQUEST['email']))  {
     //Email information
     $admin_email = "user@example.com";
     $email = $_REQUEST['email'];
     $subject = $_REQUEST['subject'];
     $comment = $_REQUEST['comment'];
     $headers = "From: $email" . "\r\n";

     mail($admin_email, $subject, $comment, $headers);
     //Email response
     echo "Thank you for contacting us!";
    }