关于"联系我们#34的问题;页

时间:2014-06-15 12:31:33

标签: php email

以下是"联系我们"的代码。页。这是错误的代码吗? 当我发送邮件时,不要去我的电子邮件! 我想要正确的写作方式吗?

<?php

if(isset($_POST['sendmail'])) {
    $to='a@example.com';
    if (mail($to,$_POST['name'],$_POST['message'])) {
        echo 'is ok';
    } else {
        echo "Error : Not Send Mail";
    }
} else {
    echo 'not ok!!!';
}
?>

1 个答案:

答案 0 :(得分:1)

试试这个:

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

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

为您的示例自定义:

<?php
if(isset($_POST['sendmail'])) {
    $to      = 'a@outlook.com';
    $subject = $_POST['name']; // I do not know if this is your email subject
    $message = $_POST['message'];
    $headers = 'From: a@outlook.com' . "\r\n" . // This will appear as to who sent the email
        'Reply-To: a@outlook.com' . "\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!!!';
}
?>