简体   繁体   中英

PHP contact form giving error

My basic contact form is giving me the error "error during sending mail". Of course, the code below is very simple and has no protection against spammers or SQL injection, but my main concern at the moment is getting the message to send.

Thanks in advance for any help given, despite the simplicity of the question.

HTML:

<form action="sendmail.php" method="post">
    <table>
        <tr>
            <td>Name:</td>
            <td><input type="text" name="Name" size="20" maxlength="40" /></td>
        </tr>
        <tr>
            <td>Email:</td>
            <td><input type="text" name="Email" size="20" maxlength="60" /></td>
        </tr>
        <tr>
            <td>Message:</td>
            <td><textarea  name="Message" maxlength="1000" cols="25" rows="6"></textarea></td>
        </tr>
    </table>
    <div align="left">
        <input name="submit" type="submit" />
    </div>
</form>

sendmail.php PHP:

<?php
    if(isset($_POST['submit'])) 
    {

        $name = $_POST['Name'];
        $email = $_POST['Email'];
        $message = $_POST['Message'];
        $from = 'From: CWON Australia';
        $to = "......@hotmail.com";
        $subject = "CWON Message";

        $content = "From: $name\n E-Mail: $email\n Message:\n $message";

        if(mail ($to, $subject, $content, $from)) {
            echo "mail has been sent";
        }
        else
        {
            echo "error during sending mail";
        }       
    }
?>

Your code is functional, and I assume you're getting the "mail has been sent" response.

If you aren't, then you'll first want to check your php.ini for the correct sendmail path (this I believe is the default):

sendmail_path = /usr/sbin/sendmail -t -i

If sendmail path is good, do you see your email in mail logs? I'd also test by mailing your user account on the server itself.

It's more likely that you're getting owned by a spam filter, especially if you're emailing to an "@hotmail.com" address.

See this SO question for some guidance

mail()函数在php中不是很可靠,并且很难配置...所以我建议您使用PHPMailer发送邮件...您可以在此处阅读有关如何使用PHPMailer发送邮件的所有信息: PHPMailer GitHUB

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM