2015-03-03 38 views
1

我知道這個問題已被問過,但我已經在這裏檢查瞭解答/答案,他們做不適用於我電子郵件表單不會發送電子郵件。無法加載資源:服務器響應的狀態爲500(內部服務器錯誤)

最初的問題是,我的服務器沒有安裝PHP,所以當我按'提交'代碼會顯示....現在它已安裝,它現在運行平穩。但我的電子郵件表格不會發送...它導致一個空白屏幕,我不斷收到錯誤控制檯說:

「無法加載資源:服務器響應狀態爲500(內部服務器錯誤)」,其是指向的HTML MYSERVER/html_form_send.php

部分:

<form name="htmlform" method="post" action="html_form_send.php"> 
<table width="450px"> 
</tr> 
<tr> 
<td valign="top"> 
    <label for="first_name">First Name *</label> 
</td> 
<td valign="top"> 
    <input type="text" name="first_name" maxlength="50" size="30"> 
</td> 
</tr> 

<tr> 
<td valign="top""> 
    <label for="last_name">Last Name *</label> 
</td> 
<td valign="top"> 
    <input type="text" name="last_name" maxlength="50" size="30"> 
</td> 
</tr> 
<tr> 
<td valign="top"> 
    <label for="email">Email Address *</label> 
</td> 
<td valign="top"> 
    <input type="text" name="email" maxlength="80" size="30"> 
</td> 

</tr> 
<tr> 
<td valign="top"> 
    <label for="telephone">Telephone Number</label> 
</td> 
<td valign="top"> 
    <input type="text" name="telephone" maxlength="30" size="30"> 
</td> 
</tr> 
<tr> 
<td valign="top"> 
<label for="Upload">Upload a CV</label> 
</td> 
<td valign="top"> 
<input type="file" name="selectedfile" /> 
</td> 
</tr> 
<tr> 
<td colspan="2" style="text-align:center"> 
    <input type="submit" value="Submit"> 
</td> 
</tr> 
</table> 
</form> 

和PHP:

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

    // CHANGE THE TWO LINES BELOW 
    $email_to = "[email protected]"; 

    $email_subject = "email subject"; 


    function die($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['first_name']) || 
     !isset($_POST['last_name']) || 
     !isset($_POST['email']) || 
     !isset($_POST['telephone']) || 
     die('We are sorry, but there appears to be a problem with the form you submitted.'); 
    } 

    $first_name = $_POST['first_name']; // required 
    $last_name = $_POST['last_name']; // required 
    $email_from = $_POST['email']; // required 
    $telephone = $_POST['telephone']; // not required 

    $error_message = ""; 
    $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
    if(!preg_match($email_exp,$email_from)) { 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
    } 
    $string_exp = "/^[A-Za-z .'-]+$/"; 
    if(!preg_match($string_exp,$first_name)) { 
    $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 
    } 
    if(!preg_match($string_exp,$last_name)) { 
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; 
    } 
    if(strlen($error_message) > 0) { 
    die($error_message); 
    } 
    $email_message = "Form details below.\n\n"; 

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

    $email_message .= "First Name: ".clean_string($first_name)."\n"; 
    $email_message .= "Last Name: ".clean_string($last_name)."\n"; 
    $email_message .= "Email: ".clean_string($email_from)."\n"; 
    $email_message .= "Telephone: ".clean_string($telephone)."\n"; 


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

<!-- place your own success html below --> 

Thank you for contacting us. We will be in touch with you very soon. 

<?php 
} 
die(); 
?> 

由於

+0

直接在瀏覽器中打開html_form_send.php文件,看看你那裏。 – 2015-03-03 11:53:10

+0

爲什麼?我只是看到代碼,如果我直接在瀏覽器中打開它? – Superunknown 2015-03-03 17:08:54

回答

2

本地web服務器或interwebs上的現場主機?如果這是一個本地的網絡服務器,那麼我建議你需要運行一個郵件服務器才能真正發送郵件(你可以從飛馬獲得一個免費的郵件服務器 - http://www.pmail.com/downloads_s3_t.htm - 它被稱爲水星郵件)

如果它是一個活的服務器在互聯網上嘗試發送一個基本的示例電子郵件使用PHP手冊中找到的標準代碼 - 如果這樣的話,那麼問題是上面的代碼

1

首先,改變「顯示錯誤」的水平,看看有什麼錯誤。但我認爲問題是,你嘗試重新申報「死」的功能:

function die($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(); 
    } 
相關問題