How can I send the email with PHP?

How can I send the email with PHP usin live server?

<?php 

  // include "contactform/contactform.php";

  if (isset($_POST['submit'])){

    $to = "[email protected]";

    $subject = "Email From Website";

    $name = $_POST['name'];

    $email = $_POST['email'];

    $message = $_POST['message'];

    $headers = "From : $email";

     $sendMail = mail($to, $subject, $message, $headers);

    if ($sendMail) {

      echo "Email sent";

    }else{

      echo "something is wrong";

    }
  }

?>


<form action="index.php" method="POST" role="form" class="contactForm">

                      <div id="sendmessage">Your message has been sent. Thank you!</div>

                      <!-- <div id="errormessage"></div> -->

                      

                      <div class="row">

                        <div class="col-md-12 mb-3">

                          <div class="form-group">

                            <input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />

                            <div class="validation"></div>

                          </div>

                        </div>

                        <div class="col-md-12 mb-3">

                          <div class="form-group">

                            <input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />

                            <div class="validation"></div>

                          </div>

                        </div>

                        <div class="col-md-12 mb-3">

                          <div class="form-group">

                            <textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for me" placeholder="Message"></textarea>

                            <div class="validation"></div>

                          </div>

                        </div>

                        <div class="col-md-12">

                          <input type="submit" name="submit" class="button button-a button-big button-rouded" value="Send Message">

                        </div>

                      </div>

                    </form>

I’m assuming you are asking this because what you are doing now doesn’t work? Are you getting the “something is wrong” output or some php error or other symptom?

The only apparent issue that would prevent the posted code from working is that these emails are NOT being sent from the email address that someone entered in the form. They are being sent from the mail server at your web hosting and the From: email address must correspond to that mail server. You can put the entered email address in a Reply-to: mail header, after validating that it is only and exactly one properly formatted email address, to prevent mail header injection.

Sponsor our Newsletter | Privacy Policy | Terms of Service