<pre><?php use PHPMailer\PHPMailer\PHPMailer; require_once(__DIR__ . '/sendEmails/vendor/phpmailer/phpmailer/src/Exception.php'); require_once(__DIR__ . '/sendEmails/vendor/phpmailer/phpmailer/src/PHPMailer.php'); require_once(__DIR__ . '/sendEmails/vendor/phpmailer/phpmailer/src/SMTP.php'); error_reporting(-1); ini_set('display_errors', 'On'); set_error_handler("var_dump"); class VerificationCode { public $smtpHost; public $sender; public $smtpPort; public $password; public $receiver; public $code; // some function to receive,send and port. public function _constructor($receiver) { $this->sender = "2023@outlook.com"; $this->password = "***"; $this->smtpHost = "smtp-mail.outlook.com"; $this->smtpPort = 587; } // function to send email(). public function sendMail(){ $mail= new PHPMailer(); $mail->isSMTP(); $mail->SMTPAuth = true; $mail->SMTPDebug = 3; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->SMTPOptions = array( 'ssl'=> array( 'verify_peer'=>false, 'verify_peer_name' => false, 'allow_self_signed'=> true ) ); $mail->Host = $this->smtpHost; $mail->Port =$this->smtpPort; $mail->IsHTML(true); $mail->Username =$this->sender; $mail->Password= $this->password; $mail->Body=$this->getHTMLMessage(); $mail->Subject = "Your verification code is {$this->code}"; $mail->SetFrom($this->sender, "Verification Code"); $mail->AddAddress($this->receiver); if($mail->send()) { echo "Mail Sent Successfully"; exit; } echo "Failed to Send Mail"; } // function to get html message from the email. public function getHTMLMessage() { $this->code=$this->getVerificationCode(); $htmlMessage=<<<MSG <!DOCTYPE html> <html> <body> <h1>Your verification code is {$this->code}</h1> <p>Use this code to verify your account.</p> </body> </html> MSG; return $htmlMessage; } // get verificationCode. public function getVerificationCode() { return (int) substr(number_format(time() * rand(), 0, '', ''), 0, 6); } } // instantiate VerificationCode and send email $vc=new VerificationCode('2023@outlook.com'); $vc->sendMail(); ?>
$this->receiver
Username
Password
$mail->SetFrom($this->sender, "Verification Code"); $mail->AddAddress($this->receiver);
2023@outlook.com
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)