GP | feat: add local PHPMailer usage
This commit is contained in:
29
send-SMTP.php
Normal file
29
send-SMTP.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
use PHPMailer\PHPMailer;
|
||||
use PHPMailer\Exception;
|
||||
|
||||
require 'PHPMailer/Exception.php';
|
||||
require 'PHPMailer/PHPMailer.php';
|
||||
require 'PHPMailer/SMTP.php';
|
||||
|
||||
$mail = new PHPMailer;
|
||||
$mail->isSMTP();
|
||||
$mail->SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
|
||||
$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->SMTPSecure = 'tls'; // ssl is depracated
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $smtpUsername;
|
||||
$mail->Password = $smtpPassword;
|
||||
$mail->setFrom($emailFrom, $emailFromName);
|
||||
$mail->addAddress($emailTo, $emailToName);
|
||||
$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!";
|
||||
}
|
||||
Reference in New Issue
Block a user