Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
include_once "PHPMailer/PHPMailer.php";
include_once "PHPMailer/Exception.php";
include_once "PHPMailer/SMTP.php";
function send_mail($to,$subject,$body){
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
$mail = new PHPMailer(true); // Passing `true` enables exceptions
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'YOUR_HOST_HERE'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'YOUR_SMTP_USERNAME'; // SMTP username
$mail->Password = 'YOUR_SMTP_PASSWORD'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
// IT SHOULD BE LIKE THIS, $mail->setFrom('', 'HackerRahul');
$mail->addAddress($to); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject; // Subject of the Email
$mail->Body = $body; // Body of the Email
$response = '1';
$response = '0';
return $response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment