PHPMailer web server code example
Example 1: phpmailer hostinger
<?php
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'YOUR PASSWORD HERE';
$mail->setFrom('[email protected]', 'Your Name');
$mail->addReplyTo('[email protected]', 'Your Name');
$mail->addAddress('[email protected]', 'Receiver Name');
$mail->Subject = 'Testing PHPMailer';
$mail->msgHTML(file_get_contents('message.html'), __DIR__);
$mail->Body = 'This is a plain text message body';
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'The email message was sent.';
}
?>
Example 2: phpmailer example php
<?php
require_once('class.phpmailer.php');
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->SMTPDebug = 1;
$mailer->Port = 587;
$mailer->Host = 'smtplw.com.br';
$mailer->SMTPAuth = true;
$mailer->Username = 'smtplocaweb';
$mailer->Password = 'Gwb9etA323';
$mailer->FromName = 'Bart S. Locaweb';
$mailer->From = '[email protected]';
a mesma caixa postal configurada no remetente do SMTP
$mailer->AddAddress('[email protected]','Nome do
destinatário');
$mailer->Subject = 'Teste enviado através do PHP Mailer
SMTPLW';
$mailer->Body = 'Este é um teste realizado com o PHP Mailer
SMTPLW';
if(!$mailer->Send())
{
echo "Message was not sent";
echo "Mailer Error: " . $mailer->ErrorInfo; exit; }
print "E-mail enviado!"
?>