Last active
July 25, 2018 22:39
-
-
Save ghacosta/be440f0954f8025713742df96eb83a6a to your computer and use it in GitHub Desktop.
Send emails using gmail SMTP and PHPMailer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 = "[email protected]"; | |
$mail->setFrom('[email protected]', 'Comercio IT'); | |
$mail->addReplyTo('[email protected]', '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