php想发送联系表单

时间:2015-04-20 11:43:05

标签: php email

我不知道为什么它不起作用。我想把联系表格发送到电子邮件,但是当我提交它时显示空白页面并且没有发送电子邮件。这里我添加了html部分也让你可以理解。我希望我能得到所有专家的好解。谢谢。

<?php
if (isset($_POST['send'])) {
  # code...
  $name = $_POST['name'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
  $ques_type = $_POST['ques_type'];
  $message = $_POST['message'];
  $formcontent=" From: $name \n Email: $email \n Phone: $phone \n Question   Type: $ques_type \n Message: $message";
  $recipient = "backoffice@simarketconsultants.com";
  $subject = "Contact Form";
  $mailheader = "From: $email \r\n";
  mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
  echo "Thank You!";
 }
?>
   
<form methos="POST" action="includes/send-form.php">
  <fieldset>
    <div class="input-group">
      <label for="name">Full Name: <sup class="red">*</sup></label>
      <input type="text" class="" name="name" placeholder="Full Name" required>
    </div>
    <div class="input-group">
      <label for="email">E-mail Address: <sup class="red">*</sup></label>
      <input type="email" class="" name="email" placeholder="example@yourdomain.com" required>
    </div>
    <div class="input-group">
      <label for="phone">Phone Number: </label>
      <input type="tel" class="" name="phone" placeholder="+445678946343">
    </div>
    <div class="input-group">
      <label for="ques_type">Question Type: <sup class="red">*</sup></label>
      <select name="ques_type" class="">
        <option for="" id="" class="" selected>Please Select Question Type</option>
        <option for="" name="customers" class="">Customer Sevice</option>
        <option for="" name="new" class="">New Accounts</option>
        <option for="" name="payments" class="">Payments</option>
        <option for="" name="marketing" class="">Marketing</option>
        <option for="" name="partners" class="">Partners</option>
        <option for="" name="technical" class="">Technical Support</option>
      </select>
    </div>
    <div class="input-group">
      <label for="message" class="adjust">Qusetions or Comments: <sup class="red">*</sup></label>
      <textarea name="message" placeholder="Your questions/comments will be written here....." required></textarea>
    </div>
    <div class="input-group">
      <input class="btn btn-danger" name="send" value="Send" type="submit">
    </div>
  </fieldset>
</form>

2 个答案:

答案 0 :(得分:3)

首先,您的表单应该说method='post'而不是methos='post'

其次,mail()不适用于localhost。考虑使用PHPMailer或在实时服务器上进行测试。

第三个(是一个单词?),确保持有php的文件位于includes/send-form.php文件中,相对于包含该表单的文件。

最后,select代码包含name属性,而不是option

示例:

<select name='car'>
  <option value='Audi'>Audi</option>
  <option value='Ford'>Ford</option>
  <option value='Skoda' selected>Skoda</option>
</select>
   
<?php 

  echo $_POST['car']; //Skoda

在您的情况下,需要阅读:

  <select name="ques_type" class="">
    <option value="none_selected" class="" selected>Please Select Question Type</option>
    <option value="customers" class="">Customer Sevice</option>
    <option value="new" class="">New Accounts</option>
    <option value="payments" class="">Payments</option>
    <option value="marketing" class="">Marketing</option>
    <option value="partners" class="">Partners</option>
    <option value="technical" class="">Technical Support</option>
  </select>

答案 1 :(得分:0)

您不应该关闭<?php标记。保持打开状态,无需关闭它,例如当你包含一个文件并希望在结束标记后面的包含空格后发送标题会导致错误。

尝试像这样调试:

TEST1:

if (isset($_POST['send'])) {
  echo 'test';
  exit;

输出“test”吗?

您是否安装了邮件服务器?