0

I'm trying to make my form work so I can receive emails. My website is currently stored on Heroku and everything looks fine, except it doesn't send emails after the form is submitted. Can someone help me please?

index.php :

<form id="contact-form" method="post" action="email.php">
    <input class="holder" placeholder="Name" type="text" name="name" required>
    <input class="holder" placeholder="Email" type="email" name="email" required>
    <textarea class="holder" placeholder="Drop me some lines" type="text" name="message"></textarea>
    <div class="button-position">
        <button id="button-submit" type="submit"><p id='submit_word'>Submit</p><img class="send-spaceship" src="resources/css/images/send-spaceship.png"></button>
    </div>
</form>

email.php:

<?php

    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $message = $_POST['message'];


    $email_from = "itzikshaoulian@gmail.com";

    $email_subject = "Form Submission";

    $email_body = "User Name: $name.\n".
                    "User Email: $visitor_email.\n".
                        "User Message: $message.\n";


    $to = "itzikshaoulian@gmail.com";

    $headers = "From: $email_from \r\n";

    $headers .= "Reply-To: $visitor_email \r\n";

    mail($to,$email_subject,$email_body,$headers);

    header("Location: https://itzikshaoulianportfolio.herokuapp.com/");
?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
ISAAC
  • 149
  • 9
  • Also, be sure to sanitize `$visitor_email`, and verify there are no new lines present. Hackers can add on other headers, and basically hijack your mail function. – Blue Aug 02 '18 at 21:05
  • Heroku doesn't support native outbound email. I recommend using the Mailgun API. – Alex Howansky Aug 02 '18 at 21:09

0 Answers0