0

I´m trying to send a email from the contact form of my static web page, but i don´t receive the message or the message is not send it for some reason.

index.html

    <form id="contac-form" action="action.php" method="post" class="row" name="contact-form">
      <div class="col-md-12 mb-3 text-center">
        <h2>GET IN TOUCH</h2>
      </div>
      <div class="field-group col-md-6">
        <div class="input">
          <input type="text" name="name" id="name">
          <label for="name">Name *</label>
        </div>
      </div>
      <div class="field-group col-md-6">
        <div class="input">
          <input type="email" name="email" id="email">
          <label for="email">Email *</label>
        </div>
        <div class="error-msn text-center" id="error-email">
          <p>Please enter a valid email.</p>
        </div>
      </div>
      <div class="field-group textarea col-md-12">
        <div class="input">
          <textarea name="message" id="message" cols="30" rows="4"></textarea>
          <label for="message">Message *</label>
        </div>
      </div>
      <div class="error-msn text-center" id="succesfull-msn">
        <p>Your message has been sended.</p>
      </div>
      <div class="error-msn text-center" id="error-msn">
        <p>Please fill all the fields.</p>
      </div>
      <div class="col-md-12 submit-btn text-left">
        <input type="button" id="submit" class="btnth" value="SEND">
      </div>
    </form>

script.js

  function emailValidation(value){
    var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    return re.test(value);
  }
  submit.on('click', function(){
    if (name.val() === '' || email.val() === '' || message.val() === '') {
      error.addClass('error');
    } else if (name.val() !== '' && email.val() !== '' && message.val() !== '') {
      error.removeClass('error');
      if (!emailValidation(email.val())) {
        console.log('here');
        erro_email.addClass('error');
      } else {
        erro_email.removeClass('error');
        succesfull_msn.addClass('error');
        contact_form.submit();
        setTimeout(function(){
          succesfull_msn.removeClass('error');
        }, 3000);
        console.log('submited');
      }
    }
  });

action.php

<?php
  $to = "mianfrigo@gmail.com"; // this is your Email address
  $from = $_POST['email']; // this is the sender's Email address
  $name = $_POST['name'];
  $subject = "Form submission";
  $subject2 = "Copy of your form submission";
  $message = $first_name . " wrote the following:" . "\n\n" . $_POST['message'];
  $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
  $header = "From: $email \r\n";

  $headers = "From:" . $from;
  $headers2 = "From:" . $to;
  mail($to,$subject,$message,$header);
  mail($from,$subject2,$message2,$header); // sends a copy of the message to the sender
?>

The form is working well, the validation work, but when the form is submitted noting really happen any idea what could be wrong here.

Miguel Frias
  • 87
  • 1
  • 1
  • 9
  • Any error messages? – Stephen Jun 12 '18 at 10:43
  • Are you doing this on localhost? Did you check your spam box? – Sehdev Jun 12 '18 at 10:44
  • Any PHP errors or warnings you receive? Or anything to be found in the server log files? – Daniel Bürckner Jun 12 '18 at 10:44
  • Are you doing this on localhost or server? if server, check whether that server supports smtp mails or not.. – sree Jun 12 '18 at 10:45
  • yes i´m testing in the localhost, i´m work with xampp server. and there no error showing on the log file. – Miguel Frias Jun 12 '18 at 10:47
  • You need to use Smtp in order to send email from the localhost – Sehdev Jun 12 '18 at 10:49
  • https://www.tinywebhut.com/send-mail-from-localhost-xampp-36 – Saral Jun 12 '18 at 10:50
  • Ok i followed the instructions from the post but still nothing, i made the changes in xampp server but nothing yet. – Miguel Frias Jun 12 '18 at 11:05
  • Ok fix one issue at least now im getting a error message `mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\therabytes\action.php on line 10` event after i made the changes xampp in the files php.ini and sendmail.ini – Miguel Frias Jun 12 '18 at 12:52

0 Answers0