2014-06-15 94 views
-5

以下是「聯繫我們」頁面的代碼。這是錯誤的代碼? 當我發送消息時,請勿去我的電子郵件! 我想要寫出正確的方法嗎?Qustion關於「聯繫我們」頁面

<?php 

if(isset($_POST['sendmail'])) { 
    $to='[email protected]'; 
    if (mail($to,$_POST['name'],$_POST['message'])) { 
     echo 'is ok'; 
    } else { 
     echo "Error : Not Send Mail"; 
    } 
} else { 
    echo 'not ok!!!'; 
} 
?> 
+1

請定義TRUE;和'wrong'這樣我們就可以選擇一個:) – Fluffeh

+0

你需要檢查這個幫助http://myphpform.com/final-form.php – Saqueib

回答

1

試試這個:

http://php.net/manual/en/function.mail.php

<?php 
$to  = '[email protected]'; 
$subject = 'the subject'; 
$message = 'hello'; 
$headers = 'From: [email protected]' . "\r\n" . 
    'Reply-To: [email protected]' . "\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 

mail($to, $subject, $message, $headers); 
?> 

爲您定製例如:

<?php 
if(isset($_POST['sendmail'])) { 
    $to  = '[email protected]'; 
    $subject = $_POST['name']; // I do not know if this is your email subject 
    $message = $_POST['message']; 
    $headers = 'From: [email protected]' . "\r\n" . // This will appear as to who sent the email 
     'Reply-To: [email protected]' . "\r\n" . // This will appear as to who to send the replies 
     'X-Mailer: PHP/' . phpversion(); 


    if (mail($to, $subject, $message, $headers)) { 
     echo 'is ok'; 
    } else { 
     echo "Error : Not Send Mail"; 
    } 
} else { 
    echo 'not ok!!!'; 
} 
?>