PHPMailer is perhaps the most popular open-source PHP library to send emails with. It was first released way back in 2001, and since then it has become a PHP developer’s favorite way of sending emails programmatically
In this this article, we’ll talk about why you should use PHPMailer
Installing PHPMailer
You can install PHPMailer using Composer:
composer require phpmailer/phpmailer
Sending Email from a Local Web Server Using PHPMailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once "vendor/autoload.php";
//PHPMailer Object
$mail = new PHPMailer(true); //Argument true in constructor enables exceptions
//From email address and name
$mail->From = "from@yourdomain.com";
$mail->FromName = "Full Name";
//To address and name
$mail->addAddress("recepient1@example.com", "Recepient Name");
$mail->addAddress("recepient1@example.com"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("reply@yourdomain.com", "Reply");
//CC and BCC
$mail->addCC("cc@example.com");
$mail->addBCC("bcc@example.com");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "Mail body in HTML";
$mail->AltBody = "This is the plain text version of the email content";
try {
$mail->send();
echo "Message has been sent successfully";
} catch (Exception $e) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
This is very Simple and easy way for sending email just copy and paste above code
Are you want to get implementation help, or modify or enhance the functionality of this script? Submit Paid Service Request Starting from Rs. 500 /-
0 Comment('s) to “Sending Emails in PHP with PHPMailer”
Leave a Reply