I have a problem with phpmailer.
<?php
require 'PHPMailer/Exception.php';
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
// $mail->isSMTP();
$mail->Host = 'smtp.google.com';
$mail->SMTPAuth = true;
$mail->SMTPAuthTLS = true;
$mail->Username = 'myemail';
$mail->Password = 'mypassword';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 587;
//Recipients
$mail->setFrom('hismail', 'Joe');
$mail->addAddress('mymail', 'OsamaMohammed');
$mail->addReplyTo("hismail");
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Mail verify';
$mail->Body = 'Thanks for siging in! Your code is 179012';
$mail->SendMail = "mymail";
// $mail->SendMail = "/usr/sbin/sendmail";
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}.
It shows me:
Sending with mail()
Sendmail path: /usr/sbin/sendmail
Envelope sender: hismail
To: OsamaMohammed mymail
Subject: Mail verify
Headers: Date: Fri, 2 Jun 2023 17:34:29 +0200From: OsamaMohammed <hismail> Reply-To: <hismail> .comMessage-ID: <ID> X-Mailer: PHPMailer 6.8.0 (https://github.com/PHPMailer/PHPMailer)MIME-Version: 1.0Content-Type: text/html; charset=iso-8859-1
Additional params: -fhismail
Result: true
Message has been sent.
Keep in mind that i have commented $mail->isSTMP()
because it doesn't connect to the STMP host.
I tried commenting $mail->STMP, but it doesn't work. I tried changing the ssl options, and I couldn't. Finally, I was trying using openssl, but I sent this question first.