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

HTML

Connecting Own HTML contact form to Email

I have written up the code for a live website (being hosted through AWS). On the website, there is a Contact Sheet. Now, I'm trying to either get the person's input to go to AWS or my MailChimp account. How do I go about doing that? Any help would be greatly appreciated!

If your hosting service has an address associated with the email you provided, you can use this with PHP mail() function as long as it is supported. I have a live website up and have an HTML form to acquire the person's name, phone, email, and message. This information is then sent to a PHP script to be handled.

Hey, that's exactly what I did but am somehow unable to get it to work. Here is the my PHP code (where I write domain-email is the email I am sending it to):

<?php // Check for empty fields if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['phone']) || empty($_POST['message']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) { echo "No arguments Provided!"; return false; }

$name = $_POST['name']; $email_address = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message'];

// Create the email and send the message $to = 'domain-email'; $email_subject = "Website Contact Form: $name"; $email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message"; $headers = "From: domain-email\n"; $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); return true;
?>

1 Answer

can you show your code?

Hey, I've posted the PHP above!