In this chapter we will learn how to use PHPmailer. This is a library that allows sending SMTP mails in PHP. 

Few important things you have to remember then you can use the code it will work for you:

If you have done the above step then you can create an index.PHP file and put the following code and replace your credentials of your gmail account.



require 'class/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); //Sets Mailer to send message using SMTP
//$mail->SMTPDebug = 3;
$mail->Host = '';

$mail->Port = '465'; //Sets the default SMTP server port
$mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables
$mail->Username = 'gmail'; //Sets SMTP username
$mail->Password = "password"; //Sets SMTP password
$mail->SMTPSecure = 'ssl'; //Sets connection prefix. Options are "", "ssl" or "tls"
$mail->From = ''; //Sets the From email address for the message
$mail->FromName = "My Company Name"; //Sets the From name of the message
$mail->AddAddress('', 'Hello John'); //Adds a "To" address
$mail->AddCC("", "Jhon"); //Adds a "Cc" address
$mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters
$mail->IsHTML(true); //Sets message type to HTML 
$mail->Subject = "Text Subject"; //Sets the Subject of the message
$mail->Body = "Text Message";

if ($mail->Send()) { //Send an Email. Return true on success or false on error
    $error = '<label class="text-success">Thank you for contacting us</label>';
} else {
    $error = '<label class="text-danger">There is an Error</label>';
// echo $mail->ErrorInfo;

echo $error;