无法从mail()php获取邮件

时间:2013-11-08 18:10:20

标签: php email

我正在使用已经具有简单联系表单功能的模板,并且流程表格非常简单,我不明白为什么我不能收到任何电子邮件...我确实运行了调试测试,它运行得很好。从我在网上看到,似乎不再支持mail()函数或实际上不发送电子邮件。也许你们可以帮助我在这里了解为什么这不起作用以及如何解决它?提前谢谢!

contact.php

<form method="post" id="contactForm" action="processForm.php">
<div class="clearfix">
    <div class="grid_6 alpha fll"><input type="text" name="senderName" id="senderName" placeholder="Name *" class="requiredField" /></div>
        <div class="grid_6 omega flr"><input type="text" name="senderEmail" id="senderEmail" placeholder="Email Address *" class="requiredField email" /></div>                             
</div>
<div><textarea name="message" id="message" placeholder="Message *" class="requiredField" rows="8"></textarea></div>
    <input type="submit" id="sendMessage" name="sendMessage" value="Send Email" />
    <span> </span>

processForm.php

<?php
// Define some constants
define( "RECIPIENT_NAME", "Jenna" );
define( "RECIPIENT_EMAIL", "your_mail@gmail.com" ); //left it standard for privacy reasons
define( "EMAIL_SUBJECT", "Visitor Message" );

// Read the form values
$success = false;
$senderName = isset( $_POST['senderName'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['senderName'] ) : "";
$senderEmail = isset( $_POST['senderEmail'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";

// If all values exist, send the email
if ( $senderName && $senderEmail && $message ) {
  $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
  $headers = "From: " . $senderName . " <" . $senderEmail . ">";
  $success = mail( $recipient, EMAIL_SUBJECT, $message, $headers );
}

// Return an appropriate response to the browser
if ( isset($_GET["ajax"]) ) {
  echo $success ? "success" : "error";
} else {
?>
<html>
  <head>
    <title>Thanks!</title>
  </head>
  <body>
  <?php if ( $success ) echo "<p>Thanks for sending your message! We'll get back to you shortly.</p>" ?>
  <?php if ( !$success ) echo "<p>There was a problem sending your message. Please try again.</p>" ?>
  </body>
</html>
<?php
}
?>

此外,当您测试时,它会返回“感谢您发送消息!...”。

编辑更新: 谢谢大家,但显然当我上传到我的服务器时它正在工作。收到电子邮件的时间比我想象的要长。我的所有代码都是正确的,并没有任何问题。谢谢你抽出宝贵的时间!

0 个答案:

没有答案