I do not know if what I want to do is possible (but finding out that it isn't would be useful in itself).
I cannot use my company's gmail account "[email protected]" directly with PHPMailer. I can, however, use an intermediary gmail account "[email protected]" which can have "less secure apps" enabled, which permits SMTP verification.
However I do not want to have the emails be sent from this [email protected] account (wouldn't look particularly professional) - but rather the company's gmail account.
I can send the emails from the intermediary account to [email protected]; either through the editing of the PHPMailer parameters, or by automatically forwarding emails from [email protected] to the company account.
The problem lies in how [email protected] can then successfully email the email (or at least appear to be the sender), as originally intended.
The code so far
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server for gmail
$Mail->SMTPDebug = 0; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "tls"; //Secure conection
$Mail->Port = 587; // set the SMTP port to gmail's port
$Mail->Username = '[email protected]'; // gmail account username
$Mail->Password = 'a_password'; // gmail account password
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Mail test';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = '[email protected]'; //Your email adress (Gmail overwrites it anyway)
$Mail->FromName = 'Testing Again';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->addAddress($personEmail); // To: the PERSON WE WANT TO EMAIL
$Mail->isHTML( TRUE );
$Mail->Body = ' Good news '.$personName.'! The email sent correctly!';
$Mail->AltBody = 'This is a test mail';
$Mail->Send();
$Mail->SmtpClose();
if(!$Mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $Mail->ErrorInfo;
exit;
}
So the issue is: not having the email sent to $personEmail from [email protected] (that's trivial) but rather how to send the email from [email protected] to [email protected] such that [email protected] forwards the message to $personEmail
TO:
$personEmail,FROM:
[email protected] via [email protected]? But this is not possible either (The comments in your code agree!(Gmail overwrites it anyway)
) – HPierce