0

I know that this is a question that has been answered lots and I've read a few of them, but I just can not seem to get my send mail function to work. So the basics are I have an HTML contact form:

<form id="contact" action="mail_handler.php" method="post">
                    <div class="col-md-6">
                      <fieldset>
                        <input name="name" type="text" class="form-control" id="name" placeholder="Your name..." required="">
                      </fieldset>
                    </div>
                    <div class="col-md-6">
                      <fieldset>
                        <input name="email" type="email" class="form-control" id="email" placeholder="Your email..." required="">
                      </fieldset>
                    </div>
                    <div class="col-md-12">
                      <fieldset>
                        <textarea name="message" rows="6" class="form-control" id="message" placeholder="Your message..." required></textarea>
                      </fieldset>
                    </div>
                    <div class="col-md-12">
                      <fieldset>
                        <button type="submit" value="Submit" class="btn">Send Message</button>
                      </fieldset>
                    </div>
                  </form>

This is attached an external file called mail_handler.php, this seems to be where I just can't get my file to work.

<?php

    $email = $_POST["email"]; //users email
    $name = $_POST["name"]; //users name
    $msg = $_POST["message"]; //users message
    $to = "email@mydomain.co.uk"; //my email
    $subject = "New online enquiry"; //subject line
    $headers = "From: $email \n"; //who is the email from 
    $message = "Name: $name \n sent the following enquiry: $msg"; //email content
    $user = "$email";
    $usersubject = "Thank You"; //subject for user email
    $userheaders = "From: enquiries@samsonvilliers.co.uk \n"; //who email is from
    $usermessage = "Thank you for sending a message, we will be in touch soon.";//thank you message to users email
    mail($to,$subject,$message,$headers); //mail to me
    mail($user,$usersubject,$usermessage,$userheaders); //mail to user
    header('Location: send_mail.html'); //send to a new page with thank you message.

?>

I have tried altering the code in many different ways, but nothing seems to work, I am sure that I am making a very simple mistake, but any guidance would be very appreciated.

Rose
  • 1
  • I'm pretty sure you probably checked this... But are you sure the email id is correct? – Debanik Dawn Oct 27 '17 at 10:37
  • check this question https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail https://stackoverflow.com/questions/20297703/mail-function-is-not-working-in-php – Chintan Mathukiya Oct 27 '17 at 10:37
  • Is it showing any errors? – d.coder Oct 27 '17 at 10:38
  • can u chk if condition in mail funtion if(mail($to,$subject,$message,$headers)) – Moorthy Oct 27 '17 at 10:39
  • Is your server configured to send emails? If you are on a hosted environment, please make sure, the hosting service allows sending mails from your sender address. I know some services, that only allow sending mails from addresses that are hosted by the same service. – iquellis Oct 27 '17 at 10:40

0 Answers0