PHP联系表单错误发送邮件

时间:2021-07-04 18:15:48

I am trying to integrate this php code to my contact form, all html inputs are fine, there must be an error in the php script, here's the code:

我试图将这个PHP代码集成到我的联系表单中,所有html输入都很好,php脚本中一定有错误,这里是代码:

    <?php
$to = 'test@email.com;
$subject = 'New Website Message';
$headers = 'From: (Website Form) <POST['email']>' . "\r\n" . 'Content-type: text/html; charset=utf-8';
$message = '
<html>
    <head>
        <title>You have received a new message!</title>
    </head>
    <body>
        <h3>Name: <span style="font-weight: normal;">' . $_POST['name'] . '</span></h3>

        <h3>Email: <span style="font-weight: normal;">' . $_POST['email'] . '</span></h3>

        <div>
            <h3 style="margin-bottom: 5px;">Message:</h3>
            <div>' . $_POST['message'] . '</div>
        </div>
    </body>
</html>';

if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['message'])) {
    if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        mail($to, $subject, $message, $headers) or die('<span style="color: red;">Error sending Mail</span>');
        echo '<span class="send-true" style="color: #00dd63;">Your email was sent!</span>';
    }
} else {
    echo '<span style="color: red;">All fields must be filled!</span>';
}
?>

1 个解决方案

#1


2  

Seems like you've a syntax error man. try this one:

好像你有一个语法错误的男人。试试这个:

    <?php
$to = 'test@email.com';
$subject = 'New Website Message';
$headers = 'From: (Website Form) <$_POST['email']>' . "\r\n" . 'Content-type: text/html; charset=utf-8';
$message = '
<html>
    <head>
        <title>You have received a new message!</title>
    </head>
    <body>
        <h3>Name: <span style="font-weight: normal;">' . $_POST['name'] . '</span></h3>

        <h3>Email: <span style="font-weight: normal;">' . $_POST['email'] . '</span></h3>

        <div>
            <h3 style="margin-bottom: 5px;">Message:</h3>
            <div>' . $_POST['message'] . '</div>
        </div>
    </body>
</html>';

if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['message'])) {
    if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        mail($to, $subject, $message, $headers) or die('<span style="color: red;">Error sending Mail</span>');
        echo '<span class="send-true" style="color: #00dd63;">Your email was sent!</span>';
    }
} else {
    echo '<span style="color: red;">All fields must be filled!</span>';
}
?>

#1


2  

Seems like you've a syntax error man. try this one:

好像你有一个语法错误的男人。试试这个:

    <?php
$to = 'test@email.com';
$subject = 'New Website Message';
$headers = 'From: (Website Form) <$_POST['email']>' . "\r\n" . 'Content-type: text/html; charset=utf-8';
$message = '
<html>
    <head>
        <title>You have received a new message!</title>
    </head>
    <body>
        <h3>Name: <span style="font-weight: normal;">' . $_POST['name'] . '</span></h3>

        <h3>Email: <span style="font-weight: normal;">' . $_POST['email'] . '</span></h3>

        <div>
            <h3 style="margin-bottom: 5px;">Message:</h3>
            <div>' . $_POST['message'] . '</div>
        </div>
    </body>
</html>';

if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['message'])) {
    if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        mail($to, $subject, $message, $headers) or die('<span style="color: red;">Error sending Mail</span>');
        echo '<span class="send-true" style="color: #00dd63;">Your email was sent!</span>';
    }
} else {
    echo '<span style="color: red;">All fields must be filled!</span>';
}
?>