I wrote some code to sends emails, but those are kept be viewed as spam. I tested it using Gmail. Can any body help me to figure out what's wrong?
I am 100% sure that the following parameters are correct:
$mail->Host
$mail->Username
$mail->Password
$mail->Subject (contains $subject)
$mail->Body (contains $message)
$mail->setFrom
$mail->addReplyTo (equals $mail->setFrom)
$to (contains mail recipient)
I also used $mail->addCustomHeader("BCC: bccmail@gmail.com")
.
Below the code. I think it's a header issue.
function php_mailer_send_mail ($to,$subject,$message) {
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
// $mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'https://xxx.xxx.xxx.xxx:XXXX'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myUsername'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('emailfrom@mydomain.com', 'Keyword Translation Factory');
$mail->addAddress($to, 'Welcome User'); // Add a recipient
$mail->addReplyTo('emailfrom@mydomain.com', 'Keyword Translation Factory');
// $mail->addCC('ccmail@gmail.com');
$mail->AddBCC('bccmail@gmail.com');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $message;
$mail->send();
// echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}