문제

I've got a WordPress site with a contact form that works fine on my MAMP environment, but when I publish to my clients WIMP server I get a failure.

  • I am not at all familiar with WIMP environments- how does one go about checking PHP error logs
  • Offhand, are there issues with PHP emailing on WIMP that would be causing this?

Code:

<?php 

if ($_POST["contact_name"]<>'') { 
    $ToEmail = 'me@domain.com'; 
    $EmailSubject = 'New contact message';  
    $mailheader = "From: ".$_POST["contact_email"]."\r\n";  
    $mailheader .= "Reply-To: ".$_POST["contact_email"]."\r\n"; 
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";  
    $MESSAGE_BODY = "<b>Name:</b> ".$_POST["contact_name"]."<br>";  
    $MESSAGE_BODY .= "<b>Email:</b> ".$_POST["contact_email"]."<br>";
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 

?> 
<h4>Your message was sent. We will be in touch with you shortly.</h4>
<?php 
} else { 
<form id="contact-form" name="contact" method="post" action="#">
<label for="contact-name">Name *</label>
<input type="text" id="contact-name" name="contact_name" tabindex="1" class="required"/>
<label for="contact-email">Email</label>
<input type="text" id="contact-email" name="contact_email" tabindex="2" class="email" />
<input type="submit" id="contact-submit" name="contact_submit" value="" tabindex="8" />
</form>
<?php 
}; 
?>
도움이 되었습니까?

해결책

Windows does not have a built in email server like unix type OSs tend to have. You need to configure php.ini to add SMTP server information through which to relay email.

다른 팁

The PHP manual page for the `mail()' function details a number of Windows-specific points. However, the main points which could affect you are in this section: (to quote)

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 <someone@example.com>". The mail command may not parse this properly while talking with the MTA.

There are a few other things to consider as well; please read the manual page for more.

Hope that helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top