提问者:小点点

另一个PHP联系人表单未发送


我已经联系上了。php文件与一个非常简单的php电子邮件提交脚本和表单。脚本和表单位于同一文件中。就我的一生而言,我无法让它在提交时发送电子邮件。如果我删除isset的If语句($\u POST['submit'],然后当页面加载时,它当然会自动发送邮件,我确实收到了。但一旦我将其设置为只处理提交,我就不会收到电子邮件。现在我正在使用一个gmail帐户,但我以后不会了。我不是php方面的专家,但通过研究,这似乎是一个非常简单的脚本。我已经尝试了许多不同的变体,现在我只想保持简单。我的表单是HTML5兼容的,我在发送前使用HTML5进行验证,所以现在我不需要任何类型的验证。我不知道为什么这不会发送。我试过不同的标题。我已经尽可能多地搜索了stackoverflow,以查看是否有任何解决方案,我已经尝试了好几次,但仍然无法发送此解决方案。

contact.php代码:

<?php
if(isset($_POST['submit']))
{
  $to = 'someone@gmail.com';
  $subject = 'Contact Form Submission';
  $name = $_POST['name'];
  $email = $_POST['email'];
  $telephone = $_POST['telephone'];
  $website = $_POST['website'];
  $message = $_POST['message'];

  $header = 'MIME-Version: 1.0' . "\r\n";
  $header .= "From: ". $email ."\r\n";
  $header .= "Reply-To: ". $email ."\r\n";
  $header .= "Content-type: text/html; charset= utf-8 \r\n";

  $body = "From: $name\n E-Mail: $email\n Telephone: $telephone\n Website: $website\n 
  Message:\n $message";

  if(mail($to, $subject, $body, $header))
  {
    echo 'Thank you! Your message has been sent. We will try to contact you within one 
    business day.';
  }
  else
  {
    echo 'There was an error with your submission. Please try again.';
  }
}
?>

<form action="contact.php" method="post">
<div>
    <label>Name</label>
    <input name="name" type="text" placeholder="Full Name" required>

    <label>E-mail</label>
    <input name="email" type="email" placeholder="someone@somewhere.com" required>

    <label>Telephone</label>
    <input name="telephone" type="tel" placeholder="xxx-xxx-xxxx" required>

    <label>Website (Optional)</label>
    <input name="website" type="url" placeholder="http://www.yoursite.com">
</div>

<div>
    <label>Message</label>
    <textarea name="message" placeholder="Type what you want here" required></textarea>

    <input id="submit" name"submit" type="submit" value="Send Message">
</div>

<div class="call">
    <span>Or call us at (555) 555-5555</span>
</div>
</form>

我还尝试对表单标记执行操作,因为它从同一个文件调用脚本,并且我尝试使用


共3个答案

匿名用户

您的代码(错误):

<input id="submit" name"submit" type="submit" value="Send Message">

您使用的是名称“submit”,而不是名称=名称“submit”

但正确的代码是:

<input id="submit" name="submit" type="submit" value="Send Message">

匿名用户

通过检查是否在发布请求中设置了所有必需的参数来替换发送电子邮件的条件。

匿名用户

试试看!

如果($_POST['提交'] == '发送消息'){

发送

}