treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Email auto reply

  • Hi!
    How would I code an auto reply to a form? In php and or javascript?
  • Once you have validated the form and stored the results you would call mail()

    Assuming your have already taken the users $_POST['email'] variable, validated it and stored it as $email further up the script then ....


    <?php
    $to = $email;
    $subject = 'Form submission at www.yoursite.com';
    $message = 'This is an auto generated response from www.yoursite.com\r\n\r\nThank you for your submission.\r\n';
    $headers = 'From: webmaster@yoursite.com' . "\r\n" .
    'Reply-To: webmaster@yoursite.com';

    mail($to, $subject, $message, $headers);
    ?>