We use a foreign open source mail class for this email sending function. The PHPMailer mail class that you may have used is very simple. Today I will talk about a simple usage tutorial. Friends in need can refer to it. At the same time Like other accessories, friends can give me your opinions.
Things to note:
1. Character set setting of the email, $mail->CharSet = "GB2312"; // Specify the character set here! Here I only specify GB2312 because this way Outlook can display the email subject normally. I have tried setting it to utf-8 but it displays garbled characters in Outlook.
2. If you are sending an email in html format, remember to also specify
3. If you want to use it to send mass emails, remember to modify the include file function, such as:
require("phpmailer/class.phpmailer.php");
Change to
require_once("phpmailer/class.phpmailer.php");
Otherwise, class redefinition will occur.
The code is as follows |
Copy code |
/*********************************
* Author: Li Yingjiang
* Date: 2006-12-7
*******************************/
require("phpmailer/class.phpmailer.php");
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: Ordinary email authentication does not require adding @domain name
$mail->Password = "mailPassword"; // SMTP password
$mail->From = "yourmail@cgsir.com"; // Sender's email address
$mail->FromName = "cgsir.comadmin"; // Sender
$mail->CharSet = "GB2312"; // Specify the character set here!
$mail->Encoding = "base64";
$mail->AddAddress($sendto_email,"username"); // Recipient email and name
$mail->AddReplyTo("yourmail@cgsir.com","cgsir.com");
//$mail->WordWrap = 50; // set word wrap
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true); // send as HTML
// Email subject
$mail->Subject = $subject;
// Email content
$mail->Body = '
Welcome to http://www.bKjia.c0m
Thank you for registering as a member of this site!
';
$mail->AltBody ="text/html";
if(!$mail->Send())
{
echo "The email was sent in error ";
echo "Mail error message: " . $mail->ErrorInfo;
exit;
}
else {
echo "$user_name email sent successfully! ";
}
}
// Parameter description (send to, email subject, email content, additional information, username)
smtp_mail('yourmail@cgsir.com', 'Welcome to cgsir.com!', 'NULL', 'cgsir.com', 'username');
?>
|
You need to download the PHPMailer file package phpmailer-1.73.tar.gz from the open source community: http://phpmailer.sourceforge.net/
http://www.bkjia.com/PHPjc/632968.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632968.htmlTechArticleFor this email sending function, we use a foreign open source email class. Everyone may have used PHPMailer. The email class is very simple. Today I will talk about a simple usage tutorial. If you need it...