【问题标题】:PHP mail script gives me syntax errorPHP邮件脚本给了我语法错误
【发布时间】:2014-11-14 18:38:19
【问题描述】:

我试图将我的 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 页面上构建一个邮件表单

【问题讨论】:

  • 这是一个 PHP 错误,还是来自任何 smtp 客户端 php 试图调用以实际执行发送的错误?
  • 尝试去掉引号:"$subject" => $subject
  • 阅读php.net/manual/en/function.mail.php - 这就是手册的目的;)就像'ol VCR's。没有一个,永远无法弄清楚如何设置时间。
  • 您确实意识到您只是在检查if (isset($_REQUEST['email'])) - 如果有人没有填写主题字段,邮件很可能会被拒绝或发送到垃圾邮件。
  • 您的代码没有问题,在我测试时没有。检查您的邮件日志,并在您打开 &lt;?php 标记 error_reporting(E_ALL); ini_set('display_errors', 1); 后将错误报告添加到文件顶部,看看它是否产生任何结果。

标签: php forms email


【解决方案1】:

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

  1. "$subject" 需要只是 $subject 。您正在捕获该变量是有原因的。所以把它变成一串“$subject”对我来说毫无意义。

希望这会有所帮助!

【讨论】:

  • 不需要action属性,因为邮件脚本在同一个页面中。没有 action 属性,表单提交到当前页面。
  • 啊!行。好点子。对不起。我的 php foo 生锈了。将编辑那个。
  • "$string" 和 $string 由于PHP string handling interpolation 而计算出相同的结果。
【解决方案2】:

试试这个代码:

   //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!";
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 2013-10-14
    • 2017-12-01
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    相关资源
    最近更新 更多