联系表格,未收到消息

时间:2014-03-05 19:40:49

标签: php forms contact

我需要制作一个联系表格而且我做了,但是当我发送测试消息我没有收到该消息时,我检查了我的电子邮件地址和测试消息从未到达那里我也查看垃圾邮件文件夹但仍然没有运气怎么样解决这个问题?这是我的代码

<?php

$formMessage = "";
$senderName = "";
$senderEmail = "";
$senderMessage = "";

if ($_POST['username']) { // If the form is trying to post value of username field

// Gather the posted form variables into local PHP variables
$senderName = $_POST['username'];
$senderEmail = $_POST['email'];
$senderMessage = $_POST['msg'];
// Make sure certain vars are present or else we do not send email yet
if (!$senderName || !$senderEmail || !$senderMessage) {

     $formMessage = "The form is incomplete, please fill in all fields.";

} else { // Here is the section in which the email actually gets sent

    // Run any filtering here
    $senderName = strip_tags($senderName);
    $senderName = stripslashes($senderName);
    $senderEmail = strip_tags($senderEmail);
    $senderEmail = stripslashes($senderEmail);
    $senderMessage = strip_tags($senderMessage);
    $senderMessage = stripslashes($senderMessage);

这是我不确定的部分

// End Filtering
    $to = "test@gmail.com";         
    $from = "contact@your_website_here.com";
    $subject = "You have a message from your website";
    // Begin Email Message Body
    $message = "
    $senderMessage

    $senderName
    $senderEmail
    ";
    // Set headers configurations
    $headers  = 'MIME-Version: 1.0' . "rn";
    $headers .= "Content-type: textrn";

    // Mail it now using PHP's mail function
    mail($to, $subject, $message, $headers);
    $formMessage = "Thanks, your message has been sent.";
    $senderName = "";
    $senderEmail = "";
    $senderMessage = "";
    } // close the else condition

   } // close if (POST condition
   ?>

这里是html表单

<form id="form1" name="form1" method="post" action="contact.php">
<?php echo $formMessage; ?>
<br />
<br />
Your Name:<br />
<input name="username" type="text" id="username" size="36" maxlength="32" value="<?php          echo $senderName; ?>" />
 <br />
 <br />
 Your Email:
 <br />
 <input name="email" type="text" id="email" size="36" maxlength="32" value="<?php echo      $senderEmail; ?>" />
    <br />
    <br />
     Your Message:
    <br />
    <textarea name="msg" id="msg" cols="45" rows="5"><?php echo $senderMessage; ?>   </textarea>
    <br />
    <br />
     <br />
     <input type="submit" name="button" id="button" value="Send Now" />
      </form>

1 个答案:

答案 0 :(得分:0)

请参阅之前在Stack Overflow上提出的this question,您只需要对XAMP配置进行一些更改。