I'm using PHPMailer linked to my gmail account.
I've required the autoloader, created a function to handle sending mail, then fire the function to test. It all looks like this:
require "PHPMailer/PHPMailerAutoload.php";
function sendMail($to, $subject, $body, $from){
//init PHPMailer
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->isHTML(true);
//connection settings
$mail->Host = "smtp.gmail.com";
$mail->Username = "xxx@xxx.com";
$mail->Password = "xxxxxxxx";
//addresses
$mail->addAddress($to);
$mail->setFrom($from);
//create email
$mail->Subject = $subject;
$mail->Body = $body;
//send email
$mail->send();
}
//sendMail(to, subject, body, from)
sendMail("xxxx@xxxxx.com", "Test Subject", "Test body", "xxxxx@xxxxx.com");
This sends the email with the correct subject and body, to the right place, but it ignores the 'from' address and the email always says it comes from the gmail account through which the email is passed. Is there anyway to configure this to work?
Note I have obviously omitted the correct account details and real to or from addresses from the code above.