Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


PHP Form Sadly Not Working...

I have been trying to implement a PHP Contact Form at the end of this page: http://www.rachelbeen.com/Elizabeth-Reverse Im not sure what Im doing wrong. It simply wont send the email. Any help would be greatly appreciated!

5 Answers

31,206 Points

I'm new to php, but I don't think anyone can help much unless you post your php code that deals with the form.

Very valid point!


    $name = trim($_POST["name"]);
    $email = trim($_POST["email"]);
    $message = trim($_POST["message"]);

    if ($name == "" OR $email == "" OR $message == "") {
        echo "You must specify a value for name, email address, and message.";

    foreach( $_POST as $value ){
        if( stripos($value,'Content-Type:') !== FALSE ){
            echo "There was a problem with the information you entered.";    

    if ($_POST["address"] != "") {
        echo "Your form submission has an error.";

    $mail = new PHPMailer();

    if (!$mail->ValidateAddress($email)){
        echo "You must specify a valid email address.";

    $email_body = "";
    $email_body = $email_body . "Name: " . $name . "<br>";
    $email_body = $email_body . "Email: " . $email . "<br>";
    $email_body = $email_body . "Message: " . $message;

    $mail->SetFrom($email, $name);
    $address = "rachelbeen@gmail.com";
    $mail->AddAddress($address, "Shirts 4 Mike");
    $mail->Subject    = "Shirts 4 Mike Contact Form Submission | " . $name;

    if(!$mail->Send()) {
      echo "There was a problem sending the email: " . $mail->ErrorInfo;

    header("Location: contact.php?status=thanks");

Well this is only a part of the code it says you require a file that is "class.phpmailer.php" do you have that file you can post?

This file does not have a mail function attached! I believe its going to be in the class.phpmailer.php file if that file exists in your project?

James Barnett
James Barnett
39,199 Points

@Rachael - Take a look at this blog post on using PHPMailer to send email via gmail hopefully that will get you started.

Randy Hoyt
Randy Hoyt
Treehouse Guest Teacher

@Rachael - How the actual sending happens depends. I talk about this in the video on sending the email, 7:00-7:55. It sounds like your server needs to use SMTP. Take a look at the article James referenced earlier or the article on the Treehouse Blog that I mention in the video for more information: