SoFunction
Updated on 2025-03-10

PHPMailer mail class uses smtp. to send mail


<?php
/*******************************
* Author: Li Yingjiang
*Date: 2006-12-7
*******************************/
require("phpmailer/");

function smtp_mail ( $sendto_email, $subject, $body, $extra_hdrs, $user_name) {
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "200.162.244.66"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "yourmail"; // SMTP username Note: Normal email authentication does not require @ domain name
$mail->Password = "mailPassword"; // SMTP password

$mail->From = "yourmail@"; // Sender's email
$mail->FromName = "Administrator"; // Sender

$mail->CharSet = "GB2312"; // Specify the character set here!
$mail->Encoding = "base64";

$mail->Address($sendto_email,"username"); // Recipient's email and name
$mail->AddReplyTo("yourmail@","");

//$mail->WordWrap = 50; // set word wrap
//$mail->AddAttachment("/var/tmp/"); // attachment
//$mail->AddAttachment("/tmp/", "");
$mail->IsHTML(true); // send as HTML
// Email Subject
$mail->Subject = $subject;
// Email content
$mail->Body = '
<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=GB2312"></head>
<body>
Welcome to <a href=""></a> <br /><br />
Thank you for registering as a member of this site! <br /><br />
</body>
</html>
';

$mail->AltBody ="text/html";
if(!$mail->Send())
{
echo "The email was sent incorrectly <p>";
echo "Mail error message: " . $mail->ErrorInfo;
exit;
}
else {
echo "$user_name The email was sent successfully!<br />";
}
}

// Parameter description (send to, email subject, email content, additional information, username)
smtp_mail('yourmail@', 'Welcome to!', 'NULL', '', 'username');

?>