2014-10-29 61 views
0

所以我做了一個發送電子郵件的腳本,它使用了post方法,因爲它使用另一種編寫信息的編程語言,並且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 

    $error_message = ""; 
    $string_exp = "/^[A-Za-z .'-]+$/"; 
    if(!preg_match($string_exp,$username)) { 
    $error_message .= 'The Name you entered does not appear to be valid.<br />'; 
    } 
    if(strlen($comments) < 2) { 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />'; 
    } 
    if(strlen($emailsubject) < 2) { 
    died($error_message); 
    } 
    if(strlen($emailmessage) < 2) { 
    died($error_message); 
    } 

    $email_message = "This information was sent by a computercraft user:\n\n"; 

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


    $email_message .= "Username: ".clean_string($username)."\n"; 
    $email_message .= "Subject: " .clean_string($emailsubject)."\n"; 
    $email_message .= "Message: \n".clean_string($emailmessage)."\n"; 


// create email headers 
$headers = 'From: ' . $username . "\r\n". 
'Reply-To: '.$username."\r\n" . 
'X-Mailer: PHP/' . phpversion(); 
mail($emailto, $emailsubject, $email_message, $headers); 
?> 

{ 
    "True", 
} 

<?php 
} 
?> 

Array 

( [型] => 8 [消息] =>未定義變量:評論 [文件] => /客戶/ C/5/1/dannysmc .com/httpd.www/ccdb/email.php [line] => 31 )

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

{ 「真」, }

我在底部爲被接收它需要該類型表的程序添加一個真正的表。

如果你能幫助將是巨大的,感謝

+1

什麼錯誤你得到 – 2014-10-29 09:34:56

+0

你在公共服務器上? – pbaldauf 2014-10-29 09:39:38

+0

PHP Mail不能在本地主機上工作 – 2014-10-29 09:40:09

回答

1

變化的代碼的東西你最後一部分這樣的瞭解更多有關該錯誤

//創建電子郵件標題

$headers = 'From: your-email-address'."\r\n". 
'Reply-To: your-email-address'."\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 
} 
?> 
+0

我明白了嗎?陣列 ( [type] => 8 [message] =>未定義變量:comments [file] => /customers/c/5/1/dannysmc.com/httpd.www/ccdb/ email.php [line] => 31 ) // mail($ emailto,$ emailsubject,$ email_message,$ headers); ?> { \t 「真」, } – 2014-10-29 09:53:27

+0

刪除'如果(strlen的($評論)<2){$ ERROR_MESSAGE。=「您輸入的評論似乎並不有效。
'; }'然後再試一次 – 2014-10-29 09:59:58

+0

它只是給了我這個: // mail($ emailto,$ emailsubject,$ email_message,$ headers); ?> { \t 「真」, } – 2014-10-29 10:15:19