Last active
March 2, 2024 11:49
-
-
Save emmgfx/7762b85e924c24f7575fe36c315ff0e7 to your computer and use it in GitHub Desktop.
Send email with PHPMailer and SMTP, default and Plesk
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 | |
date_default_timezone_set('Europe/Madrid'); | |
require_once 'PHPMailer-5.2.16/PHPMailerAutoload.php'; | |
$mail = new PHPMailer; | |
$mail->isSMTP(); | |
$mail->SMTPDebug = 2; # 0 off, 1 client, 2 client y server | |
$mail->CharSet = 'UTF-8'; | |
$mail->Host = 'localhost'; | |
$mail->Port = 25; | |
$mail->SMTPSecure = 'tls'; # SSL is deprecated | |
$mail->SMTPOptions = array ( | |
'ssl' => array( | |
'verify_peer' => true, | |
'verify_depth' => 3, | |
'allow_self_signed' => true, | |
'peer_name' => 'Plesk', | |
) | |
); | |
$mail->SMTPAuth = true; | |
$mail->Username = 'smtp username'; | |
$mail->Password = 'smtp password'; | |
$mail->setFrom('[email protected]', 'Name Surname'); | |
$mail->addAddress('[email protected]', 'Name Surname'); | |
$mail->Subject = 'Email subject'; | |
$mail->msgHTML('Email content with <strong>html</strong>'); | |
if (!$mail->send()) { | |
echo "Mailer Error: " . $mail->ErrorInfo; | |
} else { | |
echo "Message sent!"; | |
} | |
?> |
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 | |
# Include and load PHPMailer: | |
require_once 'libs/utils/PHPMailer-5.2.16/PHPMailerAutoload.php'; | |
$mail = new PHPMailer(); | |
# Config the SMTP | |
$mail->CharSet = 'UTF-8'; | |
$mail->IsSMTP(); | |
$mail->Host = ''; | |
$mail->SMTPAuth = true; | |
$mail->Username = ''; | |
$mail->Password = ''; | |
# Set the mail | |
$mail->From = ''; | |
$mail->FromName = ''; | |
$mail->AddAddress('[email protected]', 'Name Surname'); | |
$mail->Subject = ''; | |
$mail->Body = ''; | |
# Send | |
$mail->send(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment