use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(true); // passing `true` enables exceptions try { //Server settings $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output $mail->isSMTP(); // Send using SMTP $mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'youremail@gmail.com'; // SMTP username $mail->Password = 'yourpassword'; // SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged $mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above //Recipients $mail->setFrom('youremail@gmail.com', 'Mailer'); $mail->addAddress('recipient@example.com'); // Add a recipient $mail->addReplyTo('youremail@gmail.com', 'Mailer'); // Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->msgHTML('In the above example, we can see how we can use PHPMailer `msgHTML` function to set the HTML content of an email message. The HTML is passed as a string parameter to this function. Package Library: PHPMailer.Hello, World!
'); $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; }