0

I'm testing my contact form. When I fill in all the fields, he validates it and goes to my "thankyou.html" page. But I don't receive an email..also, in the console in browser he doesn't give the console logs. But he does know the thankyou.html destination. Weird.

I copy paste this form from an other working example, so I don't know if this is really stuck or there is something wrong with sending the email. Live version at: https://www.melkerhei.be/smeltkroes/contact.php

Validating the input does work.

This is my contact-form:

<form method="post" name="contact_form" action="email">
                                          <div class="mt50 row justify-content-center">

                                              <div class="col-lg-6 col-12">
                                                  <input type="text" placeholder="name" class="form-control" required>
                                              </div>
                                              <div class="col-lg-6 col-12">
                                                  <input type="email" placeholder="email" class="form-control" required>
                                              </div>
                                              <div class="col-12">
                                                  <input type="text" placeholder="subject" class="form-control" required>
                                              </div>
                                              <div class="col-12">
                                                  <textarea  placeholder="Message" name="message" class="form-control" cols="4" rows="4" required></textarea>
                                              </div>
                                              <div class="col-12">
                                                  <input name="submit" type="submit" value="submit" class="btn btn-primary form_submit"></input>
                                              </div>
                                          </div>
                                        </form>

This is the email.php file to parse the input:

<?php
console.log("here");
if (isset($_POST["submit"])) {

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

    $your_email = "myemailgmail.com";
    $contact = "Smeltkroes";
    $email_body = "You have received a new message. ". " Here are the details:\n Name: $name \n ". "Email: $email_address\n Message \n $message";
    console.log("Message here");
    mail ($your_email, $subject, $email_body, "From: $name <$email>");
    console.log("Message send");
    header ("Location: thankyou.html");
    exit();
}
sg_sg94
  • 2,248
  • 4
  • 28
  • 56
  • 2
    myemailgmail.com is not a valid email adress, I think you forgot the @ sign, additionally you cannot use javascript console.log inside php. – nr1chiefrocka Jan 09 '20 at 16:03
  • 1
    As a first step you can check the error you are receiving on `mail()` return result. e.g. `$status = mail(...);`. The result will be true or false. Also, check with your hosting provider to see if they require a certain script, they may have one that works with their system. – GetSet Jan 09 '20 at 16:04
  • @nr1chiefrocka I just edited it to blank mine – sg_sg94 Jan 09 '20 at 16:10
  • 1
    `console.log` is not a valid PHP command. This by itself could be causing your code to crash with a syntax error. use `echo` instead. (`console.log` is from JavaScript, maybe that's what you were thinking of.) – ADyson Jan 09 '20 at 16:15
  • 1
    Also, even if everything becomes alright, you might still not receive the email, because the email service might not accept your email or it might go to the spam directory. To properly send an E-mail, you will need to setup a lot of things. PHPMailer or SwiftMailer for using SMTP and other extra features when sending mail form PHP – Example person Jan 09 '20 at 16:16
  • 2
    Once you remove the console.log problem, your question is highly likely to be a duplicate of [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail). Review all the suggestions there to improve the chances of your email being a) sent successfully, and b) received successfully (note that these are two separate parts of the process - successfully sending an email does not guarantee that it will be successfully received. A lot can go wrong in the meantime.) – ADyson Jan 09 '20 at 16:17
  • 1
    @ADyson thats what I wanted to point out, php mail function will not always work. An upvote for that :) – Example person Jan 09 '20 at 16:19

0 Answers0