first time here. I have a server configured to use the mail() function however i want to use phpmailer(to use another email address to send email). I have successfully used phpmailer but unfortunately, the emails are still being sent from the email address configured for mail(). any idea what can be done?
Edit: Code
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require './lib/phpmailer/src/Exception.php';
require './lib/phpmailer/src/PHPMailer.php';
require './lib/phpmailer/src/SMTP.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 2;
$mail->Host = "smtp.gmail.com";
$mail->Port = "587"; // typically 587
$mail->SMTPSecure = 'tls'; // ssl is depracated
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "mypassword";
$mail->setFrom("[email protected]", "My email");
$mail->addAddress("[email protected]", "My Recipient");
$mail->Subject = 'Test Subject';
$mail->msgHTML("test body"); // remove if you do not want to send HTML email
$mail->AltBody = 'HTML not supported';
// $mail->addAttachment('docs/brochure.pdf'); //Attachment, can be skipped
$mail->send();
Here is the what im getting when im running the code.
2022-02-09 16:05:50 SERVER -> CLIENT: 220-mydomain.myhost.net ESMTP Exim 4.94.2 #2 Wed, 09 Feb 2022 20:05:50 0400 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2022-02-09 16:05:50 CLIENT -> SERVER: EHLO mydomain.com
2022-02-09 16:05:50 SERVER -> CLIENT: 250-mydomain.myhost.net Hello mydomain.com [::1]250-SIZE 52428800250-8BITMIME250-PIPELINING250-PIPE_CONNECT250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
2022-02-09 16:05:50 CLIENT -> SERVER: STARTTLS
2022-02-09 16:05:50 SERVER -> CLIENT: 220 TLS go ahead
SMTP Error: Could not connect to SMTP host.
2022-02-09 16:05:50 CLIENT -> SERVER: QUIT
2022-02-09 16:05:50
2022-02-09 16:05:50
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
CodePudding user response: