I am using PHP mail function to send a mail with shared hosting of GoDaddy, previously email is getting in the inbox but now I am getting email in the spam box instead of inbox.
Below is my code:
<?php
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$company=$_POST['company'];
$email=$_POST['email'];
$to = $email;
$from = $email;
$CC = 'myname@gmail.com';
$subject ="Testing";
$htmlContent = '
Dear '.$name.' from '.$company.',
\nThank you for your interest in our impact initiatives.
\nPlease reach out to us, we are happy to learn more from you!
\nAll the best,
Dev Team.
';
$headers = "From: ".$name." <".$from.">\r\n";
$headers .= "Cc: $CC";
// if($extension ==""){
$headers .= "\nMIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// }
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// if(!$extension ==""){
// $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
//
// $htmlContent = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n";
//
// $htmlContent .= "--{$mime_boundary}\n";
// }
if(mail($to, $subject, $htmlContent, $headers)) {
header("Location:index.php");
// echo "<p>mail sent to $to and $headers!</p>";
} else {
echo "<p>mail could not be sent!</p>";
}
}
?>
I have used all headers but still I am facing same issue. Kindly let me know if anything needs to change and please give me some suggestions to resolve this issue.
Thank you in advance.