I am trying to send mail through PHPMailer. Everything seems to work fine, but the mails sent to my email do not show on gmail (when using google apps) but shows in Outlook or Mobile Email. I think I'm going wrong with the headers somewhere. Please help me.
Tried this question first but got no answer.
PHPMailer File:
<?php
require('PHPMailer/class.phpmailer.php');
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
//$email_to = "info@rsadvisories.com";
//$email_subject = "Request for Portfolio check up from ".$first_name." ".$last_name;
$title = array('Title', 'Mr.', 'Ms.', 'Mrs.');
$selected_val = $_POST['title'];
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message = "Name: ".$selected_val." ".clean_string($first_name)." ".clean_string($last_name)."<br />Email id: ".clean_string($email_from)."<br />Telephone no: ".clean_string($telephone)."<br />Details: ".clean_string($comments);
$allowedExts = array("doc", "docx", "xls", "xlsx", "pdf");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "application/excel")
|| ($_FILES["file"]["type"] == "application/vnd.ms-excel")
|| ($_FILES["file"]["type"] == "application/x-excel")
|| ($_FILES["file"]["type"] == "application/x-msexcel")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) && ($_FILES["file"]["size"] <= 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] != 0)
{
echo "<script>alert('Error: " . $_FILES["file"]["error"] ."')</script>";
}
else
{
$d='upload/';
$de=$d . basename($_FILES['file']['name']);
$u=move_uploaded_file($_FILES["file"]["tmp_name"], $de);
$fileName = $_FILES['file']['name'];
$filePath = $_FILES['file']['tmp_name'];
//add only if the file is an upload
//if($u)
//echo "Uploaded!";
}
}
elseif (!(file_exists($_FILES['file']['tmp_name'])) || !(is_uploaded_file($_FILES['file']['tmp_name'])))
{
echo "<script> alert('Warning : No file uploaded, Email will be sent without attachments');</script>";
}
else
{
die("<script>alert('Invalid file'); window.location.href='main.php';</script>");
}
// create email headers
$headers = 'From: '.$email_from."
".
'Reply-To: '.$email_from."
" .
'X-Mailer: PHP/' . phpversion();
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "***";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = false;
//Username to use for SMTP authentication
$mail->Username = "***";
//Password to use for SMTP authentication
$mail->Password = "***";
//Set who the message is to be sent from
$mail->SetFrom($email_from, $first_name.' '.$last_name);
$mail->AddCustomHeader($headers);
//Set an alternative reply-to address
//$mail->AddReplyTo('replyto@example.com','First Last');
//Set who the message is to be sent to
$mail->AddAddress('***', 'Ritu Shah');
$mail->From=$email_from;
//Set the subject line
$mail->Subject = 'Request for Portfolio Check up';
//Read an HTML message body from an external file, convert referenced images to embedded, convert HTML into a basic plain-text alternative body
$mail->Body=$email_message;
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->AddAttachment($file);
$mail->AddAttachment($de);
//Send the message, check for errors
if(!$mail->Send()) {
echo "<script>alert('Mailer Error: " . $mail->ErrorInfo."')</script>";
} else {
die();
$headers1 = 'From: ***'."
".
'Reply-To: ritu@rsadvisories.com'."
" .
'X-Mailer: PHP/' . phpversion();
mail($email_from,'Re:Request for Portfolio Check up','We Have received your mail. We will contact you soon.',$headers1);
echo "<script>alert('Your request has been submitted. We will contact you soon.');window.location.href='main.php';</script>";
}
}
?>
Debug message (no file uploaded, hence could not access file):
Could not access file:
SMTP -> FROM SERVER:220-gator1545.hostgator.com ESMTP Exim 4.80 #2 Tue, 03 Sep 2013 11:35:53 -0500 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
CLIENT -> SMTP: EHLO rsadvisories.com
SMTP -> FROM SERVER: 250-gator1545.hostgator.com Hello rsadvisories.com [216.172.167.28]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
CLIENT -> SMTP: MAIL FROM:<ayushkster@gmail.com>
SMTP -> FROM SERVER:250 OK
CLIENT -> SMTP: RCPT TO:<ritu@rsadvisories.com>
SMTP -> FROM SERVER:250 Accepted
CLIENT -> SMTP: DATA
SMTP -> FROM SERVER:354 Enter message, ending with "." on a line by itself
CLIENT -> SMTP: Date: Tue, 3 Sep 2013 11:35:53 -0500
CLIENT -> SMTP: Return-Path: <ayushkster@gmail.com>
CLIENT -> SMTP: To: Ritu Shah <ritu@rsadvisories.com>
CLIENT -> SMTP: From: Ayush Khemka <ayushkster@gmail.com>
CLIENT -> SMTP: Subject: Request for Portfolio Check up
CLIENT -> SMTP: Message-ID: <cb1ac1dd52e8724a2e536ea35058be19@rsadvisories.com>
CLIENT -> SMTP: X-Priority: 3
CLIENT -> SMTP: X-Mailer: PHPMailer 5.2.6 (https://github.com/PHPMailer/PHPMailer/)
CLIENT -> SMTP: From: ayushkster@gmail.com
CLIENT -> SMTP: Reply-To: ayushkster@gmail.com
CLIENT -> SMTP: X-Mailer: PHP/5.2.17
CLIENT -> SMTP: MIME-Version: 1.0
CLIENT -> SMTP: Content-Type: multipart/alternative;
CLIENT -> SMTP: boundary="b1_cb1ac1dd52e8724a2e536ea35058be19"
CLIENT -> SMTP: Content-Transfer-Encoding: 8bit
CLIENT -> SMTP:
CLIENT -> SMTP: --b1_cb1ac1dd52e8724a2e536ea35058be19
CLIENT -> SMTP: Content-Type: text/plain; charset=iso-8859-1
CLIENT -> SMTP: Content-Transfer-Encoding: 8bit
CLIENT -> SMTP:
CLIENT -> SMTP: This is a plain-text message body
CLIENT -> SMTP:
CLIENT -> SMTP:
CLIENT -> SMTP: --b1_cb1ac1dd52e8724a2e536ea35058be19
CLIENT -> SMTP: Content-Type: text/html; charset=iso-8859-1
CLIENT -> SMTP: Content-Transfer-Encoding: 8bit
CLIENT -> SMTP:
CLIENT -> SMTP: Name: Mr. Ayush Khemka<br />Email id: ayushkster@gmail.com<br />Telephone no: 09930754012<br />Details:
CLIENT -> SMTP:
CLIENT -> SMTP:
CLIENT -> SMTP:
CLIENT -> SMTP: --b1_cb1ac1dd52e8724a2e536ea35058be19--
CLIENT -> SMTP:
CLIENT -> SMTP: .
SMTP -> FROM SERVER:250 OK id=1VGta5-0001jH-9P
CLIENT -> SMTP: quit
SMTP -> FROM SERVER:221 gator1545.hostgator.com closing connection