Skip to content

Instantly share code, notes, and snippets.

@Mauryashubham
Last active August 28, 2017 10:10
Show Gist options
  • Save Mauryashubham/22bbe352f927e704069f24faf4f59841 to your computer and use it in GitHub Desktop.
Save Mauryashubham/22bbe352f927e704069f24faf4f59841 to your computer and use it in GitHub Desktop.
Send Email using Php-Mailer in PHP
<?php
/**
*
*/
class USER
{
private $db;
//Constructor
function __construct($DBcon)
{
$this->db=$DBcon;
}
//Send Mail
function send_mail($email,$message,$subject)
{
require_once('mailer/class.phpmailer.php'); //Mailer File
$mail = new PHPMailer();
$mail->IsSMTP(); // Remove this Line , if Mail not sent
$mail->SMTPDebug = 0;
$mail->SMTPAuth= true;
$mail->SMTPSecure="ssl";
$mail->Host="smtp.gmail.com";
$mail->Port=465;
$mail->AddAddress($email);
$mail->Username="Your Email Address";
$mail->Password="Your Email Password";
$mail->SetFrom('Your Email Address');
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->Send();
return true;
}
}
?>
Download the Mailer file..from here.. https://drive.google.com/file/d/0B6jKLIMjl6BtM3hYci1TelBmSE0/view?usp=sharing
<?php
/**
@author : Shubham Maurya,
Email id : [email protected]
**/
$DB_host = "localhost";
$DB_user = "root";
$DB_pass = "";
$DB_name = "testdb"; //db name
try
{
$DBcon = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
$DBcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// echo "Done..";
}
catch(PDOException $e)
{
echo "ERROR : ".$e->getMessage();
}
include_once 'class.User.php'; //Class
$user=new USER($DBcon);
?>
<?php
/**
@author : Shubham Maurya,
Email id : [email protected]
**/
//Database
require_once 'dbconfig.php';
//Class
$reg=new USER($DBcon);
$email="your email";
$message="your message";
$subject="your subject";
//send Variables
if($reg->send_mail($email,$message,$subject))
{
if(true)
{
echo "Mail sent";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment