PASSWORD RESET

Your destination for complete Tech news

PHP

How to send mail in php using PHPMailer?

425 0
< 1 min read

To send mail in PHP using PHPMailer, you will need to install the PHPMailer library and include it in your PHP script. You can install PHPMailer using composer:

composer require phpmailer/phpmailer

Once you have installed PHPMailer, you can use the following code to send an email using PHPMailer:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

// Load Composer's autoloader
require 'vendor/autoload.php';

// Instantiate a new PHPMailer object
$mail = new PHPMailer(true);

// Set SMTP options
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.example.com';
$mail->Port = 465;
$mail->Username = 'your_username';
$mail->Password = 'your_password';

// Set email options
$mail->setFrom('[email protected]', 'From Name');
$mail->addAddress('[email protected]', 'To Name');
$mail->Subject = 'Email Subject';
$mail->Body = 'Email body';

// Send the email
$mail->send();

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.