-1

hey guys i'm trying to send a form to an email and that's my form :

<?php 
error_reporting(0);
if(isset($_POST['submit'])){
    $to = "elbiheiry2@gmail.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 . " wrote the following:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $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 "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
?>

<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>

<form action="form.php" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Image: <input type="file" name="image_name"><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html> 

every time i click submit it tells me the mail is sent but when i check my inbox i find nothing can anyone help ???

Mohamed Elbiheiry
  • 347
  • 2
  • 9
  • 25
  • SMTP is configured ? – Vaibhav Feb 07 '16 at 13:04
  • it's on localhost and that's all i did honestly , i don't know how to config SMTP u said @Vaibhav – Mohamed Elbiheiry Feb 07 '16 at 13:06
  • @Qirel i'm not getting an error it and didn't give any error , it also say it's sent and the code won't sent this message till it is sent right ? – Mohamed Elbiheiry Feb 07 '16 at 13:12
  • You don't actually check if it's sent or not. `mail()` returns a boolean `true`/`false`, so you can do `if (mail($to,$subject,$message,$headers)) { /* mail was sent */ }` - however that does not mean that it was filtered by some spam-filter or such, you should read the duplicate I posted in detail. – Qirel Feb 07 '16 at 13:14
  • @Qirel i added the line u wrote and didn't give me any thing back and that mean it's not sent , so can u help me solve it ?????? – Mohamed Elbiheiry Feb 07 '16 at 13:16
  • As I already said, read the duplicate I posted - in detail. There are many reasons as to why it's not being sent (or received), and for me to help you without anything specific to go on would be just plain guesses. Read the duplicate ;-) – Qirel Feb 07 '16 at 13:21
  • mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() that is the error i get if using the error report – Mohamed Elbiheiry Feb 07 '16 at 13:24

1 Answers1

0

I would suggest you switch to PHPMailer, it will take care of email configurations for you.

makmesh
  • 30
  • 3