PHP从联系表单发送电子邮件的麻烦

时间:2013-09-30 16:50:36

标签: php html forms email

我有一个网站启动并运行,似乎无法让PHP发送表单数据。有时会收到感谢信息但从未出现在邮件中。我的目标是让表单收集数据,然后通过电子邮件将数据发送给客户。

感谢您的帮助。我正在努力解决它会出现的问题。

<?php
$to = "********@*******.com";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$message = $_REQUEST['enquiry'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully";}
else
{print "We encountered anerror sending your mail";}
?>
<section class="container">
<section class="col-lg-6 col-lg-offset-1">
<form class="form-horizontal text-center" role="form" method="post" action="form_send.php">
  <div class="form-group">
    <label for="Name" class="col-lg-2 control-label">Name:</label>
    <div class="col-lg-6">
      <input type="name" class="form-control" id="name" name="name" placeholder="Enter Name...">
    </div>
  </div>
  <div class="form-group">
    <label for="Email" class="col-lg-2 control-label">Email:</label>
    <div class="col-lg-6">
      <input type="email" class="form-control" id="email" name="email" placeholder="Enter Email...">
    </div>
  </div>
  <div class="form-group">
    <label for="Phone" class="col-lg-2 control-label">Phone:</label>
    <div class="col-lg-6">
      <input type="phone" class="form-control" id="phone" placeholder="Enter Phone Number...">
    </div>
  </div>
  <div class="form-group">
    <label for="Enquiry" class="col-lg-2 control-label">Enquiry:</label>
    <div class="col-lg-6">
      <textarea type="enquiry" class="form-control" rows="5" id="enquiry" name="enquiry" placeholder="Enter Email..."></textarea>
    </div>
  </div>
   <div class="form-group">
    <label for="Enquiry" class="col-lg-2 control-label"></label>
    <div class="col-lg-6">
     <button class="btn btn-primary" type="submit">Send Message</button>
    </div>
  </div>
</form>

来自电子邮件服务器的回复:

永久性失败的技术细节:Google试图传递您的邮件,但服务器拒绝了aspmx.l.google.com的收件人域peoplepropertyshop.co.uk。 [2607:f8b0:4003:CO 2 :: 1A]。其他服务器返回的错误是:550-5.1.1您尝试访问的电子邮件帐户不存在。请尝试550-5.1.1仔细检查收件人的电子邮件地址是否存在拼写错误或550-5.1.1不必要的空格。要了解详情,请访问550 5.1.1 support.google.com/mail/bin/answer.py?answer=6596 t6si822722oei.44 - gsmtp

1 个答案:

答案 0 :(得分:1)

首先,您应该检查您的代码是否在一个文件中(form_send.php)。之后添加一些检查用户是否已提交表单:

if (!empty($_POST))

邮件将发送至$ to email。如果要更改它,请将$ email参数传递给mail()函数:

$sent = mail($to, $subject, $message, $headers) ;

为:

$sent = mail($email, $subject, $message, $headers);

另请检查您的邮件服务器配置并添加一些验证。

$email = htmlentities($_REQUEST['email']);
$message = htmlentities($_REQUEST['enquiry']);