2012-02-25 57 views
0

我有没有发送但正在输出消息发送的联系表单?任何人都可以看到问题吗?PHP联系表格不发送?

<?php 

$name = $_POST['name']; 
$email = $_POST['email']; 
$subject = $_POST['subject']; 
$message = $_POST['message']; 
$to = "[email protected]"; 

    //begin of HTML message 
    $message = " 
    From : $name, 
    Email: $email, 
    Subject: $subject, 
    Message: $message "; 
    //end of message 

    // To send the HTML mail we need to set the Content-type header. 
    $headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$headers .= "From: Website Enquiry"; 


if (isset($_POST['name'])) { 

     // now lets send the email. 
    mail($to, $subject, $message, $headers); 

header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=Thankyou, we will be in touch shortly.'); 

} else { 
    header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=There was an error sending your message, Please try again.'); 
    } 

?> 
+2

为了使电子邮件API更健壮和连贯,为什么不考虑实施[SwiftMailer](http://swiftmailer.org)? – Treffynnon 2012-02-25 14:16:53

+1

此服务器是否安装了SMTP程序? – 2012-02-25 14:17:28

+0

是的,它是罗德里克... – Liam 2012-02-25 14:17:58

回答

0

的“从”头应该有一个语法正确的电子邮件地址。您还需要检查“邮件”功能的返回值。

$header .= "From: Website Enquiry <[email protected]>"; 

PS:请改善您的代码格式。

0

尝试在From:$ header中输入电子邮件。 像$headers .= "From: [email protected]"$headers .= "From: Website Enquiry <[email protected]>"

你应该将其更改为

if(mail(...)) { 
//success 
} 
else { 
//email failed 
}