0

I wrote a php script to sent email from web form when use clicks a button. The mail is working but it show this warning message in the inbox : "this mail might not have been sent from [email protected]". Here is my php code:

<?php
if(isset($_POST['send'])){

    $to = '[email protected]';
    $subject = 'Booking';

    $message = 'Name:' . $_POST['name'] . "\r\n\r\n";
    $message .= 'Email:' . $_POST['email'] . "\r\n\r\n";
    $message .= 'Phone:' . $_POST['message'] . "\r\n\r\n";

    $headers = "From:" .$_POST['email'] . "\r\n\r\n";
    $headers .= 'Content-Type: text/plain; charset=utf-8';

    $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
    if($email){
        $headers .= "\r\nReply-To: $email";
    }

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

    if(isset($success) && $success){ ?>
         <h4 style="font-family: Arial; color: #777777;">Thank You, your mail has been sent. We will be in touch with you very soon.</h4>
    <?php }else{
        echo "Sorry, there was a problem sending your message";
    }
}
?>

is there any way to do away with this disturbing message? Thank you

7
  • If your email is reaching the sender , then why not using errror_reporting(0); ? Commented Mar 14, 2015 at 4:38
  • @SulthanAllaudeen error_reporting() is a PHP function. The warning message is appearing in the message in the recipients InBox where there's no PHP involved. Commented Mar 14, 2015 at 4:43
  • Sorry i thought that the error was thrown once triggering email. Thanks :) Commented Mar 14, 2015 at 4:45
  • @Indra : What is the from address you having in the $_POST['email'] because some servers handle that too. Try using real email address Commented Mar 14, 2015 at 4:47
  • @SulthanAllaudeen I have used genuine email address in $_POST['email]. Commented Mar 14, 2015 at 4:52

1 Answer 1

2

The below code it will work try this..

<?php
$contact_name=$_POST['contact_name'];
$contact_email=$_POST['contact_email'];
$contact_phone=$_POST['contact_phone'];
$contact_message=$_POST['contact_message'];
$to_email = '[email protected]'; //you can give email id to whom you need to send
$html = 'your custom body of the mail';
$subject = 'you subject' . $contact_message;
$message = $html;
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ABC' . "\r\n"; //DONT GIVE SPACE IN "ABC"  //you can replace your value but no space.. if u give space you can get email in spam only..
$response = mail($to_email,$subject,$message,$headers);
if($response)
{
    echo "Mail sent";
}
else
{
    echo "Not sent.. Try later";
}
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.