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
ryanloerzel
12,671 PointsBuild an Interactive Website > Form Validation and Manipulation
I'm using easyPHP DevServer
Here is a look at the contact.php file from the project files:
<?php
$to_email = "bakeon@smellslikebakin.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");
exit();
}
die("Your data is invalid.");
?>
I changed: $to_email = "bakeon@smellslikebakin.com"; to: $to_email = "(my email)";
I'm using easyPHP development server and everything looks correct on the form. However, when I wrote a message and submitted the form on localhost, I expected to receive an email but nothing happened. How do I get my forms to actually email the message?
1 Answer
Hampton Paulk
5,093 PointsGood Morning. Do you have any data from your systems server error logs? This could be a sendmail/smtp configuration issue from your local development environment. I would start in the server logs.
ryanloerzel
12,671 Pointsryanloerzel
12,671 PointsThanks Hampton. This is what my error log looks like:
I'm new to Apache (and working with servers in general) so I'm not completely clear on what this means.
ryanloerzel
12,671 Pointsryanloerzel
12,671 PointsOkay I think I have things figured out. First, I had to add a header to my contacts.php:
Then I had a new error: PHP Warning: mail(): Failed to connect to mailserver...
I'm just testing on /localhost and I found out that my WAMP doesn't include a mail server, so I downloaded smtp4dev which lets me test that the mail is getting sent out.
Now it seems to be working
Hampton Paulk
5,093 PointsHampton Paulk
5,093 PointsGreat job Ryan.