0

我在通过联系表发送电子邮件时遇到问题 我无法确定问题出在哪里 我认为我做的一切都是正确的,但我在这里接受建议,希望您能帮助我。

<?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';
        }
    }
?>
4

1 回答 1

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';
        }
    }
?>
于 2012-10-03T09:43:32.613 回答