Home > Article > Backend Development > Parsing an example of using PHPMailer to send emails in PHP (example of 126.com)_PHP Tutorial
require_once('../class.phpmailer.php');
$mail= new PHPMailer();
$body= "I finally sent the email successfully! Haha! goodboy xxxxxxx "
//Send mail using SMTP
$mail->IsSMTP();
//Mail server
$mail->Host = "smtp.126.com";
$ mail->SMTPDebug = 0;
//Use SMPT authentication
$mail->SMTPAuth = true;
//Username for SMTP authentication
$mail->Username = "xxxxxxx @126.com";
//The secret of SMTP authentication
$mail->Password = "password";
//Set the encoding format
$mail->CharSet = "utf- 8";
//Set the theme
$mail->Subject = "Test";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer! ";
//Set the sender
$mail->SetFrom('xxxxxxx@126.com', 'test');
//Send email in html format
$mail-> ;MsgHTML($body);
//Recipient email name
$mail->AddAddress("xxxxxxx@126.com", "test");//Send email
if(!$ mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}