2015-12-13 82 views
-1

我已經嘗試了幾個版本的PHP表單郵件,不能讓他們任何工作。我試圖讓它在哪裏,當用戶點擊「提交」時,表單上的信息會自動發送/填充到電子郵件中。目前,沒有電子郵件正在發送,並且它停留在黑色網站xxxx.com/contact.php上。我一直在努力工作,這一點,一個星期都無濟於事,甚至是閱讀許多其他類似的帖子PHP不發送電子郵件,留在空白頁

這裏後我的HTML表單:

<form method='post' action='contact.php'> 
      <br> 
      <br> 
      <br> 
      <br> 

    <h2> 
     Contact Us Form 
    </h2> 
    <table> 
     <tr> 
      <td> 
    <p> 
     Fill out the form below with your contact information and questions/comments and click submit. 
     We will respond to your inquiry as soon as possible via email. If you prefer a different contact 
     method then please provide required information and notate your preference in the comments section. 
     I look forward to providing you and your family with great memories that last a lifetime. 
    </p> 
      </td> 
     </tr> 
    </table> 
    <br> 
    <br> 

    <label> 
     Your name:<br> 
    </label> 
    <input type="text" name="customername" size='40' maxlength='50' required><br> 

    <label> 
     Your Email:<br> 
    </label> 
    <input type='email' name='emailaddress' size='20' maxlength='254' required><br> 

    <label> 
     Your phone number (example: 555-555-1234):<br> 
    </label> 
    <input name='telephone' type='tel' size=3>-<input type='tel' size=3>-<input type='tel' size=4><br> 

    <label> 
     What product are you interested in?<br> 
    </label> 
    <input type='radio' name='newshoot' value='new'>New Photo Shoot 
    <input type='radio' name='existingshoot' value='existing'>Existing Photo Shoot 
    <input type='radio' name='prints' value='prints'>Interested in prints 

    <label> 
     Street Adress:<br> 
    </label> 
    <input type="text" name="streetaddress" size='40' maxlength='50'><br> 

    <label> 
     City:<br> 
    </label> 
    <input type="text" name="city" size='40' maxlength='50'><br> 

    <label> 
     State:<br> 
    </label> 
      <input type="text" name="state" size='40' maxlength='50'><br> 

    <label> 
     Zipcode:<br> 
    </label> 
      <input type="text" name="zipcode" size='40' maxlength='50'><br> 

    <label> 
     What country are you located in?<br> 
    </label> 
     <select> 
      <option value="USA">United States</option> 
      <option value="AFG">Afghanistan</option> 

     </select><br> 

    <label> 
     Comments:<br> 
    </label> 

     <textarea name='customercomment' rows='5' cols='60' text-align='left' wrap='hard'> 

輸入您的意見在這裏

<input type='submit' name='submit' value='Send' /> 
    <input type='reset' value='Reset'/> 

</form> 

這裏是我的PHP:

<?php 

$email_to = "[email protected]"; 

$email_subject = "Inquiry from: "($customername);  

$first_name = $_POST['customername']; 

$email_from = $_POST['emailaddress']; 

$telephone = $_POST['telephone']; 

$newshoot = $_POST['newshoot']; 

$existingshoot = $_POST['existingshoot']; 

$prints = $_POST['prints']; 

$streetaddress = $_POST['streetaddress']; 

$city = $_POST['city']; 

$state = $_POST['state']; 

$zipcode = $_POST['zipcode']; 

$comments = $_POST['customercomment']; 




$email_message = "Form details below.\n\n". 
"Customer Name: ($customername).\n Email: ($email_from).\n Telephone: ($telephone).\n New Shoot? ($newshoot).\n Existing Shoot? ($existingshoot).\n Prints? ($prints).\n Customer's address: ($streetaddress)($city)($state)($zipcode).\n Comments:($comments).\n"; 



if ($_POST['submit']) 
{ 
    mail($email_to, $email_subject,$email_message, $email_from) { 
     header('Location: index.html'); 
    } 
} 


?> 
+1

什麼是'mail($ email_to,$ email_subject,$ email_message,$ email_from){'看起來你錯過了'if if'那裏。使用錯誤報告.. – chris85

+1

首先,爲什麼你在'header()'周圍花括號?你不小心忘了添加一個'if'嗎?另外,你的'$ email_from'包含'「From:」'?檢查這兩個。另外,您的錯誤日誌是否包含任何錯誤? – k97513

+0

$ email_from = $ _POST ['emailaddress']; 不,它不。 ('Location:index.html');如果($ _POST ['submit']) { } 我改變了這個以添加'if'並取出周圍的標題,仍然不起作用。 很小問題。你指的是什麼錯誤日誌? –

回答

-2

英語新應該在文件中添加檢查點,並且你可以看到它是否有效。

if ($_POST['submit']) 
    { 
     $statu=mail($email_to,$email_subject,$email_message); 
mail($email_to,$email_subject,$email_message); 
    if($statu==TRUE) 
    echo 'email has sent !'; 
    else 
    echo 'email did not send !'; 
    } 

編輯:原諒我所有的朋友,我不想寫這樣的東西,但我不得不。我試圖幫助他說他看到了一個空白頁面,所以他可能會關閉顯示錯誤 。所以我寫了這個答案,看看頁面上是否有錯誤。他認爲這是不正確的。但它幫助他看到了他的錯誤。然而,他並不感謝,他還命令我「更新你的帖子......」抱歉,但我認爲這不是很難禮貌。

+0

你在這裏提出什麼?你在答案的代碼中沒有看到任何奇怪的東西? – chris85

+0

如果你得到一個空白頁面可能你關閉顯示錯誤:所以也許有一個錯誤。如果你添加了檢查點,你可以理解你的代碼工作,或者如果沒有錯誤,它不會工作,它會告訴你郵件已經發送 –

+0

你正在看這段代碼'mail($ email_to,$ email_subject,$ email_message,$ email_from) {'? – chris85