0

I use this code in order for a contact form. But it doesn't work! I don't get the email once submitted. Does anyone notice why it doesn't work?

<?php 
if(isset($_POST['submit'])){
    $to = "myemail@yahoo.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $subject = "Form submission";
    $subject2 = "Copy of your form submission";
    $message = $first_name . " " . $last_name . " a scris urmatoarele:" . "\n\n" . $_POST['message'];
    $message2 = "Aici este o copie al mesajului tau, " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "<script type='text/javascript'>alert('Mesaj trimis. Multumim, " . $first_name . ", va vom contacta cat de curand posibil!')</script>";
  
    //header('Location: index.html');
    }
?>
<div class="container">
 <form action="sendemail.php" method="post">
First Name: <input type="text" name="first_name" required placeholder="Your name.."><br>
Last Name: <input type="text" name="last_name" required placeholder="Last Name..."><br>
Email: <input type="text" name="email" required placeholder="Your email..."><br>
Message:<br><textarea rows="5" name="message" placeholder="Write something..." cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>

  </form>
</div>
Atul Sharma
  • 9,397
  • 10
  • 38
  • 65
Sami H
  • 11
  • 2
  • The webserver where your code is being executed most probably does not have `mail()` function configured or enabled. – Ahs N May 15 '17 at 11:53
  • are you sending mail from localhsot?? then it wont go as from localhost its not possible – Exprator May 15 '17 at 11:54
  • i send mail using a godaddy server. The code looks good to you? Maybe you'are right @AhsN. – Sami H May 15 '17 at 11:55

0 Answers0