Skip to content

Instantly share code, notes, and snippets.

@daniel-990
Forked from porfidev/Constantes.php
Created January 28, 2021 22:01
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 daniel-990/b848dd9296654cd5991275a8b26b1b20 to your computer and use it in GitHub Desktop.
Save daniel-990/b848dd9296654cd5991275a8b26b1b20 to your computer and use it in GitHub Desktop.
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