Skip to content

Instantly share code, notes, and snippets.

@emmgfx
Last active March 2, 2024 11:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmgfx/7762b85e924c24f7575fe36c315ff0e7 to your computer and use it in GitHub Desktop.
Save emmgfx/7762b85e924c24f7575fe36c315ff0e7 to your computer and use it in GitHub Desktop.
Send email with PHPMailer and SMTP, default and Plesk
<?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@domain.tld', 'Name Surname');
$mail->addAddress('email@domain.tld', '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!";
}
?>
<?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@domain.tld', '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