Fox
Fox

Reputation: 121

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 = "[email protected]";
        $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";
        }       
    }
?>

Upvotes: 0

Views: 56

Answers (2)

TipuZaynSultan
TipuZaynSultan

Reputation: 783

The mail() function is not very reliable in php and it is hard to configure... So I recommend you use the PHPMailer to send your mails... You can read all about how to send mail using PHPMailer in here : PHPMailer GitHUB

Upvotes: 0

fin
fin

Reputation: 333

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

Upvotes: 1

Related Questions