通过与我们联系表格发送电子邮件时出现问题

时间:2018-07-30 06:53:46

标签: php email contactus

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 ='xxx@company.net';
  $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";
}
}
?>

如果我将电子邮件ID设置为 xxx@company.net xxx@gmail.com ,我将从此表单中收到电子邮件,但是如果我将其设置为 xxx@company.com ,然后我没有从“与我们联系”表格中收到任何邮件...

有人可以帮助解决此问题吗?

Outlook中所需的任何设置(例如gmail中的设置),我们都必须将其设置为“安全性较低” ??

1 个答案:

答案 0 :(得分:0)

您还应该使用标头,也可以使用PHPMailer / SMTP(https://github.com/PHPMailer/PHPMailer

$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";
}