0

刚回到我放弃了一段时间的项目。我在页面(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
}
?>

所有这些代码都是从各种在线示例中混合在一起的,如果能帮助我清理混乱,我们将不胜感激!

4

2 回答 2

0

If you are using Windows (From http://php.net/mail):

Note:

The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP.

As such, the to parameter should not be an address in the form of "Something ". The mail command may not parse this properly while talking with the MTA

于 2012-09-13T16:14:11.390 回答
0

好的!问题解决了

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

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

谢谢大家

于 2012-09-13T22:37:34.787 回答