-2

I have Index.html where i have created the form with some basic fields

 <form class="modal-content animate" action="mail.php" method="post">


        <div class="container-form">
          <label for="full_Name"><b>Full Name</b></label>
          <input type="text" placeholder="Full Name" id="full_Name" name="full_Name" required>

          <label for="telephone_Number"><b>Mobile Number</b></label>
          <input type="text" placeholder="Mobile Number" name="telephone_Number" required>

          <label for="message"><b>Email Id</b></label>
          <input type="text" placeholder="Email Id" name="email_Address" required>
          <button type="submit" name = "submit" id="submit" class="read-more">Submit</button>
        </div>
      </form>

and i have include mail.php

     <?php 
if(isset($_POST['submit'])){
    $to = $_POST['email_Address']; // this is your Email address
    $from = $_POST['xyz@gmail.com']; // this is the sender's Email address
    $full_Name = $_POST['full_Name'];
    $telephone_Number = $_POST['telephone_Number'];
    $subject = "Form submission";
    $message = " Dear". "$full_Name . ". "Thanks for contacting " . $telephone_Number . " wrote the following:" . "\n\n" . $_POST['message'];

    $headers[] = 'MIME-Version: 1.0';
    $headers[] = 'Content-type: text/html; charset=iso-8859-1';

    // Additional headers . Your to email id.
    $headers[] = 'From:  <'.$from.'>'; 

    // If you want to add To, Cc and Bcc use this additional headers
    $headers[] = 'To: <'.$to.'>'; 

// Mail it
mail($to, $subject, $message, implode("\r\n", $headers));
    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.
    // You cannot use header and echo together. It's one or the other.
    }
?>

but when i click on submit button It shows "Mail Sent. Thank you, we will contact you shortly." but was not received any mail.

Aditya
  • 53
  • 1
  • 9
  • I believe that your mail function return true but receiver doesn't get any mail, In this case this [link](https://stackoverflow.com/questions/17195280/php-mail-function-return-true-but-no-message) will be helpfull – Paritosh Mahale Nov 14 '19 at 05:33

1 Answers1

2

1). How can you get this $from = $_POST['abc@gmail.com']; ?. From your form code i think you should use like this $from = $_POST['email_Address'];.

2) From PHP manual https://www.php.net/manual/en/function.mail.php.

Multiple extra headers should be separated with a CRLF (\r\n).

UPDATED : You are not using headers here and passing wrong parameters to mail() function. Use the below code

// To send HTML mail, the Content-type header must be set. I think you are missing this
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';

// Additional headers . Your to email id.
$headers[] = 'From:  <'.$to.'>'; 

$cc_email= "somecc@email.id"
$bcc_email = "somebcc@email.id"
// If you want to add To, Cc and Bcc use this additional headers
$headers[] = 'To: Mary <'.$to.'>'; // to email ID
$headers[] = 'Cc: '.$cc_email; // Cc email ID
$headers[] = 'Bcc: '.$bcc_email; // Bcc email ID

// Mail it
mail($to, $subject, $message, implode("\r\n", $headers));
iamatstackoverflow
  • 402
  • 2
  • 4
  • 13