Skip to content

Instantly share code, notes, and snippets.

@ghacosta
Last active July 25, 2018 22:39
Show Gist options
  • Save ghacosta/be440f0954f8025713742df96eb83a6a to your computer and use it in GitHub Desktop.
Save ghacosta/be440f0954f8025713742df96eb83a6a to your computer and use it in GitHub Desktop.
Send emails using gmail SMTP and PHPMailer
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require '../vendor/autoload.php';
function sendemail($para, $nombre, $cuerpo, $asunto) {
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "guillac124@gmail.com";
$mail->setFrom('guillac124@gmail.com', 'Comercio IT');
$mail->addReplyTo('noreply@educacionit.com', 'No Reply');
$mail->addAddress($para, $nombre);
$mail->Subject = $asunto;
$mail->Body = $cuerpo;
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment