2014-06-15 42 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!!!'; 
} 
?>