Skip to content

Instantly share code, notes, and snippets.

Embed
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": "elporfirio@gmail.com"
}
]
}
<?php
define('EMAIL_SENDER', 'test@email.com');
define('EMAIL_PASSWORD', 'your-secret-password');
<?php
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->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = EMAIL_SENDER;
$mail->Password = EMAIL_PASSWORD;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
// Destinatario
$mail->setFrom(EMAIL_SENDER, 'Mailer');
$mail->addAddress('elporfirio@gmail.com');
// Mensaje
$mail->isHTML(true);
$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.';
$mail->send();
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.