联系我们页面脚本无效

时间:2014-10-20 10:38:53

标签: php html5

我已经在我的网站上编写代码联系我们页面但是它不起作用。我检查了所有内容但是当我自己尝试时我仍然没有收到电子邮件。

我有这个表格:

<form id="contact-form"  class="cform" method="post">
          <label class="hide" 
                 for="author">
          Full Name
          </label>
          <input class="input-fields" id="full_name" name="full_name" type="text" required="required" placeholder="Full Name" value=""/>
          <label class="hide" for="email">Email</label>
          <input class="input-fields req-email" id="email" name="email" type="text" required="required" placeholder="Email Address" value=""/>
          <label class="hide" for="subject_title">Subject title</label>
          <input class="input-fields" id="subject_title" name="subject_title" type="text" required="required" placeholder="Subject Title" value=""/>
          <label class="hide" for="comment">Message</label>
          <textarea id="comment" class="input-fields form-control" required placeholder="Message" name="comment" cols="40" rows="200"></textarea>
          <input name="submit" type="submit" id="submit-contact-info" class="contact-info-submit form-submit-button span2" value="Send message">
        </form>

这是php:

<?php 
 if(isset($_POST['submit'])){
     $to        = "mail@asrhouse.com"; // this is your Email address
     $from      = $_POST['email']; // this is the sender's Email address
     $full_name = $_POST['full_name'];
     $subject   = $_POST['subject_title'];
     $subject2  = "Copy of your form submission";
     $message   = $full_name . " wrote the following:" . "\n\n" . $_POST['comment'];
     $message2  = "Here is a copy of your message " . $full_name . "\n\n" . $_POST['comment'];

 $headers   = "From:" . $from;
 $headers2  = "From:" . $to;
 mail($to,$subject,$message,$headers);
 mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
 $msgss= "Mail Sent. Thank you " . $full_name . ", we will contact you shortly.";
 // You can also use header('Location: thank_you.php'); to redirect to another page.
   }
    ?>

1 个答案:

答案 0 :(得分:0)

这可以帮助您了解如何格式化电子邮件。您缺少电子邮件中的重要标题信息。我猜你的电子邮件是垃圾邮件,因为你使用的方法可能会在没有合适标题的情况下将其推送到垃圾邮件。或者希望这种格式可以帮助您解决问题。如果没有错误,我们无法为您做很多事情,我们也不知道您的盒子的配置。也许它不支持PHP Mail功能?

<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";

mail($to,$subject,$message,$headers);
?>