2013-10-31 81 views
0

我想製作一個表格,將數據發佈到我的電子郵件中。HTML form PHP post to email

我發現下面的代碼,它工作正常,但我沒有從窗體中得到任何電子郵件。

這裏是PHP文件

<?php 

    // Contact subject 
    $name ="$name"; 

    // Details 
    $address="$address"; 
    $id="$id"; 
    $passport="$passport"; 
    $issue="$issue"; 
    $mula="$mula"; 
    $tamat="$tamat"; 
    $tel="$tel"; 
    $select_dd="$select_dd"; 
    $date="$date"; 
    $textarea="$textarea"; 
    $file="$file"; 



    // Mail of sender 
    $email="$email"; 

    // From 
    $header="from: $name <$mail>"; 

    // Enter your email address 

    $to ='[email protected]'; 
    $send_contact=mail($to,$subject,$message,$header); 

    // Check, if message sent to your email 
    // display message "We've recived your information" 
    if($send_contact){ 
    echo "We've recived your contact information"; 
    } 
    else { 
    echo "ERROR"; 
    }?> 
+1

那麼,你是否定義了'$ subject'和'$ message'?你可能會遇到一個錯誤。 – putvande

+0

erm對不起,你是什麼意思..我只是在5個小時前學習haha –

+0

'mail($ to,$ subject,$ message,$ header);',你只定義了'$ to'和'$ header'。您還需要定義其他2。你5個小時前學過了嗎?你的意思是5小時前開始學習PHP? – putvande

回答

0

如果我沒有記錯的話,你需要設置SMTP服務器調用郵件之前()。

ini_set('SMTP','mySMTP.serv'); 

乾杯

編輯:

Caution 
(Windows only) When PHP is talking to a SMTP server directly, if a full stop is found 
on the start of a line, it is removed. To counter-act this, replace these occurrences 
with a double dot. 

<?php 
$text = str_replace("\n.", "\n..", $text); 
?> 

如果你剛開始學習的基本規則之一是始終RTM你開始使用一個功能之前。這裏是PHP郵件功能的鏈接http://us3.php.net/manual/en/function.mail.php

+0

把ini_set放在php文件中? –

+0

是的,或者在配置文件中更好,如果有的話。您是在Windows還是Linux上使用 –

+0

? –

0

你在哪裏試過這段代碼?本地或在服務器上?是否在服務器上安裝並正確配置了sendmail(或類似軟件)?

報價從PHP - Mail Function

重要的是要注意,只是因爲郵件被接受交付,這並不意味着該郵件實際上會達到預期的目標。

您應該檢查服務器上的配置並檢查郵件日誌和垃圾郵件文件夾。

+0

我在服務器上試試。 謝謝,我會盡力做到這一點.. –