Last active
January 28, 2021 22:01
-
-
Save porfidev/ca7a3b18b1d62fcc320fd754a902d762 to your computer and use it in GitHub Desktop.
PHPMailer Tutorial 2019
This file contains 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
{ | |
"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": "[email protected]" | |
} | |
] | |
} |
This file contains 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 | |
define('EMAIL_SENDER', '[email protected]'); | |
define('EMAIL_PASSWORD', 'your-secret-password'); |
This file contains 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; | |
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('[email protected]'); | |
// 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