刚回到我放弃了一段时间的项目。我在页面顶部有一个简单的表单(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
}
?>
所有这些代码都是通过各种在线示例混合在一起的, 任何帮助清理我的烂摊子都将不胜感激!
答案 0 :(得分:0)
如果您使用的是Windows(来自http://php.net/mail):
注意:
mail()的Windows实现在很多方面与Unix实现有所不同。首先,它不使用本地二进制文件来编写消息,而只是在直接套接字上运行,这意味着需要在网络套接字(可以在本地主机或远程机器上)上侦听MTA。
其次,自定义标题如From:,Cc:,Bcc:和Date:首先不是由MTA解释,而是由PHP解析。
因此,to参数不应该是“Something”形式的地址。在与MTA交谈时,mail命令可能无法正确解析此问题
答案 1 :(得分:0)
Okie Dokie!解决问题
似乎因为电子邮件地址与域名相同,它试图在本地处理电子邮件。与链接帖子完全相同的问题。
全部谢谢