PHP联系表单返回成功,但不发送任何内容[重复]

PHP联系表单返回成功,但不发送任何内容[重复]

问题描述:

This question already has an answer here:

I'm working on a personal portfolio website (www.corybolles.com) and I'm attempting to create a contact from based off of PHP. I have very little knowledge of PHP compared to HTML and CSS, and I was wondering if anyone could help me figure out why this is not working correctly.

HTML

<div id="contact">
            <form action="contact.php" method="post">
                <label>Name</label><br>
                <input class="forminput" type="text" name="cf_name" width="50px"><br>
                <label>Email</label><br>
                <input class="forminput" type="text" name="cf_email" width="50px"><br>
                <label>Message</label><br>
                <textarea class="forminput" name="cf_message" cols="18" rows="10"></textarea><br>
                <input class="formbutton" type="submit" name="submit"value="Send">
                <input class="formbutton" type="reset"  name="clear" value="Clear">
            </form>
        </div>

PHP

<?php

$name = $_POST['cf_name'];
$email = $_POST['cf_email'];
$message = $_POST['cf_message'];
$from = 'From: www.corybolles.com'; 
$to = 'jcbollesjr@gmail.com';
$subject = 'Message from user via www.corybolles.com';

$body = "From: $name
 E-Mail: $email
 Message:
 $message";

?>

<?php

if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
    echo '<p>Thanks! Your message has been sent!</p>';
} else {
    echo '<p>Sorry, something appears to have broken. Please try again</p>';
    }
}   

?>

You can test it yourself, but whenever I fill out the form to test it, it returns a successful message, however doesn't actually send anything.

</div>

Try this in a seperate file to check if mail is actually 'working', as your current code looks fine.

<?php
echo mail('your@address.com', 'your@address.com', 'test');
?>

This script tries to send an email to your@address.com, from your@address.com, and echoes the return value of the function. If it doesn't echo 'TRUE' or '1', there is a weird problem. If it does, and you don't receive any mails in your mailbox, you should contact your server administrator.

It may be your server. If you don't own it, contact your system administrator. Possible causes could be: closed ports, packet filtering or security systems (such as SELinux) in your server or within the local network.

Look into PHPMailer which allows you to send mail via SMTP. This will mean that you have a store of all the emails that have been sent out, and will lower the risk of your mail being sent into user's spam folders!