Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
PHPMailer Tutorial 2019
"name": "elporfirio/php-mailer",
"description": "Esta es una prueba de envio de email *UPDATE* 2020",
"type": "project",
"require": {
"phpmailer/phpmailer": "^6.1"
"authors": [
"name": "elporfirio",
"email": ""
define('EMAIL_SENDER', '');
define('EMAIL_PASSWORD', 'your-secret-password');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
require 'Constantes.php';
// Al pasar true habilitamos las excepciones
$mail = new PHPMailer(true);
try {
// Ajustes del Servidor
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Comenta esto antes de producción
$mail->Host = '';
$mail->SMTPAuth = true;
$mail->Username = EMAIL_SENDER;
$mail->Password = EMAIL_PASSWORD;
$mail->Port = 587;
// Destinatario
$mail->setFrom(EMAIL_SENDER, 'Mailer');
// Mensaje
$mail->Subject = 'Esta es una prueba de email';
$mail->Body = 'Hola mundo desde <b>phpmailer</b>';
$mail->AltBody = 'Este es un mensaje para los clientes que no soportan HTML.';
echo 'Se envio el mensaje';
} catch (Exception $e) {
echo "Algo salio mal al intentar enviar: {$mail->ErrorInfo}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.