Skip to content

Instantly share code, notes, and snippets.

@cosminpopescu14
Created June 3, 2018 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosminpopescu14/33aff9b426402b91c0a6a27f90aa6f38 to your computer and use it in GitHub Desktop.
Save cosminpopescu14/33aff9b426402b91c0a6a27f90aa6f38 to your computer and use it in GitHub Desktop.
snippef for sending mail with php and php mailer
<?php
/**
* Created by PhpStorm.
* User: cosmi
* Date: 03-Jun-18
* Time: 3:55 PM
*/
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once 'vendor/autoload.php';
$mail = new PHPMailer();
//Enable SMTP debugging.
$mail->SMTPDebug = 3;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "adresa_ta@gmail.com";
$mail->Password = "parola_ta";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "tls";
//Set TCP port to connect to
$mail->Port = 587;
$mail->From = "adresa_ta@gmail.com";
$mail->FromName = "cosmin popescu";
$mail->addAddress("adresa_destinatar", "nume");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTMLLLLLL</i>";
$mail->AltBody = "un text";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment