2014-10-30 143 views
-1

所以我写了一个电子邮件脚本,但由于某种原因,它现在不工作,我甚至不记得改变它...我想我改变了回声输出,但是当我恢复它回到旧版本,它仍然无法正常工作,所以我不知道我在做什么错误,我把它通过一个PHP检查器,它回来了,因为代码是好的!电子邮件脚本不工作(PHP)

这是我的代码,请帮忙!

<?php 
if(isset($_POST['username'])) { 

function died($error) { 
    // your error code can go here 
    echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
    echo "These errors appear below.<br /><br />"; 
    echo $error."<br /><br />"; 
    echo "Please go back and fix these errors.<br /><br />"; 
    die(); 
} 

// validation expected data exists 
if(!isset($_POST['username']) || 
    !isset($_POST['emailto']) || 
    !isset($_POST['emailsubject']) || 
    !isset($_POST['emailmessage'])) { 
    died('We are sorry, but there appears to be a problem with the form you submitted.');  
} 

$username = $_POST['username']; // required 
$emailto = $_POST['emailto']; // required 
$emailsubject = $_POST['emailsubject']; // required 
$emailmessage = $_POST['emailmessage']; // required 


function clean_string($string) { 
    $bad = array("content-type","bcc:","to:","cc:","href"); 
    return str_replace($bad,"",$string); 
} 

$email_message = clean_string($emailmessage); 
$email_message .= "\n\nNOTE: Sent from a ComputerCraft User (Using L2P Live Email Client).\n"; 


// create email headers 
$headers = "From: " . $username ."@dannysmc.com \r\n". 
'Reply-To: ' . $username . '@dannysmc.com '."\r\n" . 
"Return-Path: [email protected]\r\n" . 
'X-Mailer: PHP/' . phpversion(); 

if(mail($emailto, $emailsubject, $email_message, $headers)){ 
    echo 'TRUE'; 
}else{ 
    echo '<pre>'; 
print_r(error_get_last()); //it will show you the error. Remove it on production 
} 
?> 

//mail($emailto, $emailsubject, $email_message, $headers); 
?> 


<?php 
} 
?> 
+0

在这里发布错误? – 2014-10-30 09:19:32

+0

请定义“不工作”! – 2014-10-30 09:27:45

+0

你在哪里使用它?在共享主机或本地主机上? – 2014-10-30 09:28:15

回答

0

检查了代码。

它发送电子邮件。

我发现的唯一问题是,您在错误的地方关闭了一个php标记。

?> 

//mail($emailto, $emailsubject, $email_message, $headers); 
?> 

删除注释邮件函数之前的结束标记。