Issue in sending email from contact us form

47 views Asked by At

mail.php

 <?php    
function goback()
{ 
    header("refresh:5; url=index.php");
    exit;
}
if(isset($_POST['submit'])){

  $name = $_POST['name'];
  $comment = $_POST['comment'];
  $mob = $_POST['mob'];
  $email= $_POST['email'];

  $to ='[email protected]';
  $subject= 'Request callback form';
  $message ="Name: ".$name."\n".
            "Comment: ".$comment."\n".
            "Mobile: ".$mob."\n".
            "E-mail: ".$email;           


  if(mail($to, $subject, $message)){        
    echo "Sent successfully! Thank you. ".$name.
    ", We will contact you soon!";
    goback();
  }
else 
{
  echo "something went wrong";
}
}
?>

I am getting email from this form if I set email id to [email protected] or [email protected], But if I set it to [email protected] then I didnt received any mail from contact us form ...

can anyone help to fix this?

any setting required in outlook like in gmail we have to set it to "less security" ??

1

There are 1 answers

0
Rohit Guleria On

you should use headers as well or you can use PHPMailer/SMTP (https://github.com/PHPMailer/PHPMailer) as well

$subject = 'Subject Here';
$from = 'From email';
$to = $email;       
$message = 'Your query has been successfully submitted';  

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: <$from>" . "\r\n";

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

if($mail){
   echo  "Done";
}else{
   echo "error";
}