Sending email using PHP

By | January 28, 2018

Whenever i send an email to gmail, I got the following response

was rejected due to classification as CONFIRMED SPAM.

https://github.com/PHPMailer/PHPMailer

Use the button on the right ‘Download ZIP’ to download the source files

I still could not get to use the encrypted servers ( TLS)

Following is code that works,

<?php
require “PHPMailerAutoload.php”;
$mail = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = “mail.justin-joseph.org”; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication

$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = “”; // SMTP account username
$mail->Password = “”; // SMTP account password

$mail->SetFrom(’email@justin-joseph.org’, ‘First Last’);

$mail->AddReplyTo(“email@justin-joseph.org”,”First Last”);

$mail->Subject = “Hello from a dear f riend”;
$mail->Body = ‘This is the HTML message body <b>in bold!</b>’;

$address = “justincs4@gmail.com”;
$mail->AddAddress($address, “Justin Joseph”);

if(!$mail->Send()) {
echo “Mailer Error: ” . $mail->ErrorInfo;
} else {
echo “Message sent!”;
}

?>