提交联系表格

时间:2012-10-03 09:39:14

标签: php email sendmessage

我在通过联系表单发送电子邮件时遇到问题 我无法确定问题出在哪里我认为我已经做好了一切,但我在这里接受建议,希望你能帮助我。

<?php
    if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['body']) && isset($_POST['subject'])){
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['body'];
        $subject = $_POST['subject'];
        $to = 'samir1986@gmail.com';
        $header = 'From: '.$name.'<'.$email.'>';
        if(!empty($name) && !empty($email) && !empty($body)){
            mail($to, $subject, $message,$header);
            echo 'An e-mail have been sent successfully';
        }
        else{
            echo 'Please try sending e-mail again';
        }
    }
?>

1 个答案:

答案 0 :(得分:0)

请确保您已检查过每个字段的值(出于安全原因),然后执行以下操作:

<?php
    if(!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['body']) && !empty($_POST['subject'])){
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['body'];
        $subject = $_POST['subject'];
        $to = 'samir1986@gmail.com';
        $header = 'From: '.$name.' <'.$email.'>'."\r\n";
        if (mail($to, $subject, $message, $header))
        {
            echo 'An e-mail have been sent successfully';
        }
        else
        {
            echo 'Please try sending e-mail again';
        }
    }
?>