PHPMailer is the most popular code for sending email from PHP. It involves simple integration technique to send a email.
Key Features :
- Integrated SMTP support
- Compatible with PHP 5.0 and later
- Multipart/alternative emails for mail clients that do not read HTML email
- Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encoding
Example to send a SMTP email:
Download the package form phpmailer GitHub, Extract the zip format file and find the below php files in it.
- class.phpmailer.php
- class.smtp.php
- class.pop3.php
<?php
require 'class.phpmailer.php';
require 'class.smtp.php';
require 'class.pop3.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP();
$mail->Host = 'smtp.secure.com';
$mail->SMTPAuth = true;
$mail->Username = 'secure@secure.com'; // SMTP username
$mail->Password = 'secure'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Accept SSL/TLS
$mail->Port = 465; // TCP port to connect to
$mail->From = 'name@secure.com';
$mail->FromName = 'Padmanaban Mailer';
$mail->addAddress('testing@gmail.com','Padmanaban');//Recipient
$mail->addReplyTo('info@secure.com', 'Information');
$mail->addCC('cc@secure.com');
$mail->addBCC('bcc@secure.com');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}