2012-07-15 134 views
2

我讓它工作了一分鐘,我不知道我做了什麼來阻止它工作。它仍然帶我到另一頁上提交,但我的電子郵件絕對沒有活動。聯繫表格不發送

HTML

<form id="contact_form" action="sendemail.php" method="post"> 
    <p><label>Name:<br /> 
     <input type="text" name="name" class="textfield" value="" /> 
    </label></p> 

    <p><label>Email: <br /> 
     <input type="text" name="email" class="textfield" value="" /> 
    </label></p> 

    <p><label>Phone Number: <br /> 
     <input type="text" name="phone" class="textfield" value="" /> 
    </label></p> 

    <p><label>Detail: <br /> 
     <textarea name="detail" class="textarea" cols="45" rows="5"></textarea> 
    </label></p> 

    <p><input type="submit" name="submit" class="button" value="Submit" /></p> 
</form> 

PHP

<?php 
$name = $_REQUEST['name']; 
$email = $_REQUEST['email']; 
$phone = $_REQUEST['phone']; 
$detail = $_REQUEST['detail']; 

$message = "Name: $name\nEmail: $email\nPhone Number: $phone\nDetail: $detail" ; 

mail("[email protected]", "You have recieved a message", "Information Requested:\n\n$message", "From: $email") ; 

header("location: http://mywebsite.com/thanks.html"); 

?> 
+0

你收到任何錯誤消息,這將您的垃圾郵件文件夾 – Austin 2012-07-15 22:56:31

+0

? – 2012-07-15 22:57:15

+1

您是否設置了郵件服務器? – patricksweeney 2012-07-15 23:00:49

回答

0

許多服務器都有一個I/O電子郵件的限制。它在嘗試代碼時發生過一次。也許這只是這個,或者 - 正如奧斯汀所說 - 也許這條消息被髮送到您的電子郵件地址的SPAM文件夾。

嘗試檢查您的網絡服務器日誌,看看它是否包含更多信息。

0

你應該定義頁眉和做一些改進,嘗試使用此代碼:

// As you know that you form uses POST method, you can use $_POST instead of $_REQUEST 
$name = $_POST['name']; 
$email = $_POST['email']; 
$phone = $_POST['phone']; 
$detail = $_POST['detail']; 

// Headers 
$headers = "From: =?utf-8?B?".base64_encode ('Sender Name')."?= <[email protected]>\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=utf-8\r\n"; 

// As the content is HTML, you shoud use <br /> instead of \n to break line 
$message = "Name: $name<br />Email: $email<br />Phone Number: $phone<br />Detail: $detail" ; 

// Trying to send the message 
if (mail('[email protected]', "=?utf-8?B?".base64_encode('Message subject')."?=", $message, $headers)) 
    header("location: http://mywebsite.com/thanks.html"); 
else 
    echo 'Message fail'; 
0

檢查您的垃圾/垃圾郵件文件夾。如果消息是不存在的,試試這個代碼:

<?php 
$name = $_REQUEST['name']; 
$email = $_REQUEST['email']; 
$phone = $_REQUEST['phone']; 
$detail = $_REQUEST['detail']; 

$message = "Name: $name\nEmail: $email\nPhone Number: $phone\nDetail: $detail" ; 

var_dump(mail("[email protected]", "You have recieved a message", "Information Requested:\n\n$message", "From: $email")); 

//header("location: http://mywebsite.com/thanks.html"); 
?> 

如果郵件發送成功,它將返回bool(true),否則將返回bool(false),如果它失敗了。

此外,請確保電子郵件地址是正確的...

0

您是否有任何錯誤?使用ini_set('display_errors', true)並參閱。


你應該改變$_REQUEST$_POST,因爲$_REQUEST時,應使用你不知道數據來自何處(GET,POST或COOKIE)。我們看到來自POST的數據,因爲您將表單的方法指定爲POST。

您還應該檢查這些變量是否使用isset()empty()來設置。


@Marcio Simao
頭是沒有必要的腳本工作。這是可選參數。

+2

您將增加很多郵件進入垃圾郵件文件夾的機會,因此強烈建議您定義它們 – 2012-07-15 23:34:02

0

可能這是因爲HTML的,如果它向你展示var_dump()bool(true) ...

嘗試推出從標籤的輸入域...通常被用於爲即將到來的字段標籤。不把該領域的標籤標記下......這樣的:

<p><label>Name:<br /> 
    <input type="text" name="name" class="textfield" value="" /> 
</label></p> 

但先用var_dump()檢查你的PHP代碼。

0

你可以使用

<?php  
if(isset($_POST['submit'])){  
$name = $_POST['name']; 
... other info 
$message = "Name: $name\nEmail: $email\nPhone Number: $phone\nDetail: $detail"; 
mail("[email protected]", "You have recieved a message", "Information Requested:\n\n$message", "From: $email") ; 
    header("location: http://mywebsite.com/thanks.html"); 
} 
?> 
0

嗨親切,如果其工作檢查您的郵件()。

if(mail($to, $subject, $message, $headers)){ 
    // Working 
} 

如果不是好心做郵件功能的標準格式

$name = $_REQUEST['name']; 
$email = $_REQUEST['email']; 
$phone = $_REQUEST['phone']; 
$detail = $_REQUEST['detail']; 


$subject = "Subject"; 
$headers = "From: \"".$youremail." ".$youremail."\" <".$youremail.">\n"; 
$headers .= "To: \"".$email."\" <".$email.">\n"; 
$headers .= "Return-Path: <".$email.">\n"; 
$headers .= "MIME-Version: 1.0\n"; 
$headers .= "Content-Type: text/HTML; charset=ISO-8859-1\n";  

$message = "Your Message here!"; 

if(mail($to, $subject, $message, $headers)){ 
    // success 
}