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! While you're at it, check out some resources Treehouse students have shared here.

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


Joseph Hall
Joseph Hall
10,865 Points

Why cant the mail function for a php contact form be used in MAMP?

Hi, I followed along on the smells like bakin website, and I wanted to try out the contact form with my email address. When I submit the form, nothing happens when I look in my inbox!

My Code:


<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Smells Like Bakin' Cupcake Company</title> <link rel="stylesheet" href="css/normalize.css" type="text/css" media="screen"> <link rel="stylesheet" href="css/grid.css" type="text/css" media="screen"> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen"> <link href='http://fonts.googleapis.com/css?family=Nunito:400,300,700' rel='stylesheet' type='text/css'> <script src="external/matchmedia.js"></script> <script src="picturefill.js"></script> <meta name="viewport" content="width=device-width, initial-scale = 1.0, user-scalable = no"> </head>


<div class="container clearfix">
    <div id="logo" class="grid_4">
        <object data="img/logo.svg" type="image/svg+xml" class="logo">
            <a href="logo.svg" >
                <!--[if lte IE 8 ]-->
                <img src="img/logo.gif" alt="Smells Like Bakin">

    <div id="nav" class="grid_8 omega" >
            <li class="about"><a href="#">About</a></li>
            <li class="pricing"><a href="pricing.html">Cupcakes & Prices</a></li>
            <li class="locations"><a href="locations.html">Locations</a></li>
            <li class="contact"><a href="contact.html">Contact Us</a></li>

    <div class="grid_12">
        <h1 class="hero">We have a wide variety of delicious desserts that are sure to take you by surprise!</h1>

    <div id="form" class="grid_12 omega">
        <h2>Contact Smells Like Bakin'</h2>
        <form action="contact.php" method="POST">

                <label for="name">Name:</label>
                <input name="name" id="name" type="text" class="required">
                <span>Please enter your name</span>

                <label for="email">Email:</label>
                <input name="email" id="email" type="text" class="required"> 
                <span>Please enter a valid email address</span>

                <label for="subject">Subject:</label>
                <input name="subject" id="subject" type="text"> 
                <span>Please enter your subject</span>

                <label for="message">Message</label>
                <textarea name="message" id="message" class="required"></textarea> 
                <span>Please enter your message</span>
            <p class="submit">
                <input type="submit" value="Submit" class="btn-submit">


    <div id="footer" class="grid_12">
        <div id="about" class="grid_7">
            <h2>Inside the Kitchen</h2>
            <p>Smells Like Bakin’ started out in the garage of the husband wife duo Allison &amp; Joseph. Allison is the baker, and Joseph found a way for them to make a business out of her tasty treats. Flash forward to today and they have a successful store front, catering business and cupcake truck. </p>
            <p><a href="#" class="btn-small">Read More</a></p>

        <div id="contact" class="grid_5 omega">
            <h2>Get Bakin’ with Us</h2>
            <p>Call us: <span class="contact">1-800-CUP-CAKE</span><br>
                Email us: <a href="#">bakeon@smellslikebakin.com</a></p>

                <p>We announce all of our new flavors first through Facebook &amp; Twitter, and even take requests!</p>     

                <object data="img/facebook.svg" type="image/svg+xml">
                    <a href="facebook.svg">
                        <!--[if lte IE 8 ]-->
                        <img src="img/facebook.gif" alt="Facebook">

                <object data="img/twitter.svg" type="image/svg+xml">
                    <a href="twitter.svg">
                        <!--[if lte IE 8 ]-->
                        <img src="img/twitter.gif" alt="Twitter">

            <div id="copyright" class="grid_12">
                <p>© 2012 Smells Like Bakin' Cupcake Company. All Rights Reserved.</p>



    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/validEmail.js"></script>
    <script type="text/javascript">
        var $submit = $(".submit input");
        var $required = $(".required");
        function containsBlanks(){
            var blanks = $required.map(function(){ return $(this).val() == "";});
            return $.inArray(true, blanks) != -1;

        function requiredFilledIn(){
            if(containsBlanks() || !$("#email").validEmail()) 

        $("#form span").hide();
            //Check all required fields.

        $("#email").validEmail({on:"keyup", success:function(){
        }, failure:function(){


contact.php: <?php

$to_email = "jhallpilot@gmail.com";

$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];

$subject = "[Contact Form] " . $_POST["subject"];

function isValidEmail($email) {
    return strpos($email, "@") !== false;

if($name != "" && $email != "" && $message != "" && isValidEmail($email)) {

$full_message = "Name : ". $name . "\n";
$full_message .= "Email : ". $email . "\n";
$full_message .= "Message :\n\n". $message . "\n";

mail($to_email, $subject, $full_message);
header("location: contact.html");


die("Your data is invalid.");


3 Answers

Casey Ydenberg
Casey Ydenberg
15,622 Points

WAMPs and MAMPs do not have any kind of mail server installed. To actually send email, you have to a) post your page to a real webserver, or b) configure PHPMailer and a third party SMTP. You can check out the beginner PHP learning adventure to learn how to do that.

Also, just my personal experience but XAMPP is wayyy more easy to work with than MAMP.

Good luck!

Also, just my personal experience but XAMPP is wayyy more easy to work with than MAMP.

Good luck!