0

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\n E-Mail: $email\n Message:\n $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.

  • 1
    I've had a similar issue before, then I found my server was blocking the mails going through. If the code is correct, then it could be something to do with your server? – Vagish Apr 26 '14 at 21:49
  • I tried what you suggested Jethro, and it did return with '1' so it seems like i need to contact the server. Thanks again! – user3502694 Apr 26 '14 at 22:05

3 Answers3

1

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.

1sloc
  • 1,180
  • 6
  • 12
1

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.

Peque
  • 13,638
  • 11
  • 69
  • 105
1

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!

Luke Madhanga
  • 6,871
  • 2
  • 43
  • 47