PHP邮件未发送,尽管得到了积极回应


PHP mail not sending, despite positive response

刚刚回到一个我放弃了一段时间的项目。我在页面顶部有一个简单的表单(debatecalendar.com),它出现在按钮上。

我填写了表格,收到了成功通知,但似乎没有收到任何电子邮件。不知道如何修复错误。感谢您的帮助!

主页上的代码是

// Init the form once the document is ready
jQuery( init );

// Initialize the form
function init() {
  // Hide the form initially.
  // Make submitForm() the forms submit handler.
  // Position the form so it sits in the centre of the browser window.
  jQuery('#contactForm').hide().submit( submitForm ).addClass( 'positioned' );
  // When the "Send us an email" link is clicked:
  // 1. Fade the content out
  // 2. Display the form
  // 3. Move focus to the first field
  // 4. Prevent the link being followed
  jQuery('a[href="#contactForm"]').click( function() {
    jQuery('#content').fadeTo( 'slow', .2 );
    jQuery('#contactForm').fadeIn( 'slow', function() {
      jQuery('#senderName').focus();
    } )
    return false;
  } );
  // When the "Cancel" button is clicked, close the form
  jQuery('#cancel').click( function() {
    jQuery('#contactForm').fadeOut();
    jQuery('#content').fadeTo( 'slow', 1 );
  } ); 
  // When the "Escape" key is pressed, close the form
  jQuery('#contactForm').keydown( function( event ) {
    if ( event.which == 27 ) {
      jQuery('#contactForm').fadeOut();
      jQuery('#content').fadeTo( 'slow', 1 );
    }
  } );
}

// Submit the form via Ajax
function submitForm() {
  var contactForm = jQuery(this);
  // Are all the fields filled in?
  if ( !jQuery('#senderName').val() || !jQuery('#senderEmail').val() || !jQuery('#message').val() ) {
    // No; display a warning message and return to the form
    jQuery('#incompleteMessage').fadeIn().delay(messageDelay).fadeOut();
    contactForm.fadeOut().delay(messageDelay).fadeIn();
  } else {
    // Yes; submit the form to the PHP script via Ajax
    jQuery('#sendingMessage').fadeIn();
    contactForm.fadeOut();
    jQuery.ajax( {
      url: contactForm.attr( 'action' ) + "?ajax=true",
      type: contactForm.attr( 'method' ),
      data: contactForm.serialize(),
      success: submitFinished
    } );
  }
  // Prevent the default form submission occurring
  return false;
}
// Handle the Ajax response
function submitFinished( response ) {
  response = jQuery.trim( response );
  jQuery('#sendingMessage').fadeOut();
  if ( response == "success" ) {
    // Form submitted successfully:
    // 1. Display the success message
    // 2. Clear the form fields
    // 3. Fade the content back in
    jQuery('#successMessage').fadeIn().delay(messageDelay).fadeOut();
    jQuery('#senderName').val( "" );
    jQuery('#senderEmail').val( "" );
    jQuery('#message').val( "" );
    jQuery('#content').delay(messageDelay+500).fadeTo( 'slow', 1 );
  } else {
    // Form submission failed: Display the failure message,
    // then redisplay the form
    jQuery('#failureMessage').fadeIn().delay(messageDelay).fadeOut();
    jQuery('#contactForm').delay(messageDelay+500).fadeIn();
  }
}

然后在processForm.php中处理表单,读取

<?php
// Define some constants
define( "RECIPIENT_NAME", "Debate Calendar" );
define( "RECIPIENT_EMAIL", "events@debatecalendar.com" );
define( "EMAIL_SUBJECT", "Feedback or Add Event" );
// 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>" ?>
  <p>Click your browser's Back button to return to the page.</p>
  </body>
</html>
<?php
}
?>

所有这些代码都是从各种在线示例中拼凑而成的,如果能帮我收拾残局,我将不胜感激!

如果您使用的是Windows(Fromhttp://php.net/mail):

注:

mail()的Windows实现在许多方面与Unix实现不同。首先,它不使用本地二进制文件来编写消息,而是只在直接套接字上操作,这意味着需要MTA侦听网络套接字(可以在本地主机上,也可以在远程机器上)。

其次,像From:、Cc:、Bcc:和Date:这样的自定义标头最初不是由MTA解释的,而是由PHP解析的。

因此,to参数不应该是"Something"形式的地址。在与MTA 对话时,邮件命令可能无法正确解析此信息

Okie Dokie!问题已解决

在这里找到答案:http://www.therevcounter.com/technology-computing-gadgetry/58477-php-mail-fails-send-domain-email.html

似乎是因为电子邮件地址与域相同,所以它试图在本地处理电子邮件。与链接帖子完全相同的问题。

感谢所有