I am trying to send an email with PHP mail()
function when the form is submitted. Excluding GMAIL, emails are going to spam/junk, I have tried yahoo and outlook as other email service providers.
I know there are other solutions as well, like PHP mailer or sending an email using third-party services like SendGrid or Mailgun, but I want to know if there is any other way to bypass spam filter in other email providers like I am currently bypassing Gmail.
Mail.php
<?php
function autoResponderEmail($name, $email) {
$subject = "Thank you for submitting the form";
$from = "email@example.com";
$organization = "Organization Name Here";
$message = "Thank you " . $name ." for contacting us. We will be in touch with you shortly." . "\n\n" . "Regards,\n" . $organization . " Team";
$headers .= "Reply-To: ".$organization." <".$from.">\r\n";
$headers .= "Return-Path: ".$organization." <".$from.">\r\n";
$headers .= "From: ".$organization." <".$from.">\r\n";
$headers .= "Organization: ".$organization."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
$sendMail = mail($email, $subject, $message, $headers);
if ($sendMail) {
header('Location: ./index.html');
} else {
alert('Failed to send email');
}
}
if(isset($_POST['submit'])){
$to = "email@example.com";
$organization = "Organization Name Here";
$full_name = $_POST['full_name'];
$from = $_POST['email_address'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$detail .= "Name: " . $full_name . "\r\n";
$detail .= "Email: " . $from . "\r\n";
$detail .= "Phone: " . $phone . "\r\n";
$detail .= "Subject: New Contact Inquiry" . "\r\n";
$detail .= "Organization: " . $organization . "\r\n";
$detail .= "Message: " . $message . "\r\n";
$headers .= "Reply-To: ".$organization." <".$to.">\r\n";
$headers .= "Return-Path: ".$organization." <".$to.">\r\n";
$headers .= 'Cc: waqas.jamal@sixlogs.com' . "\r\n";;
$headers .= "From: ".$organization." <".$to.">\r\n";
$headers .= "Organization: ".$organization."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
$sendMail = mail($to, $subject, $detail, $headers);
if ($sendMail) {
autoResponderEmail($full_name, $from);
} else {
alert('Failed to send email');
}
};
?>