Skip to content

Instantly share code, notes, and snippets.

@RocketFever22
Created December 30, 2021 06:20
Show Gist options
  • Save RocketFever22/309f1dd1d300063de9afd82f6e5e4c1a to your computer and use it in GitHub Desktop.
Save RocketFever22/309f1dd1d300063de9afd82f6e5e4c1a to your computer and use it in GitHub Desktop.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../extras/PHPMailer/src/Exception.php';
require '../extras/PHPMailer/src/PHPMailer.php';
require '../extras/PHPMailer/src/SMTP.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
$mail->SMTPSecure = 'tls'; // ssl is depracated
$mail->SMTPAuth = true;
/*
Esto es lo que se suele cambiar
*/
$mail->Host = "smtp.gmail.com"; // use $mail->Host = gethostbyname('smtp.gmail.com'); // if your network does not support SMTP over IPv6
$mail->Port = 587; // TLS only
$mail->Username = "";
$mail->Password = "";
$mail->setFrom("email@remitente.com");
$mail->addAddress('email@destino.com');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("test body"); //$mail->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded,
$mail->AltBody = 'HTML messaging not supported';
// $mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file
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