What to note:
1. The character set of the message, $mail->charset = "GB2312"; This specifies the character set! I only specify GB2312 here because Outlook displays the subject of the message correctly, I tried to set it to utf-8 but it appears garbled in Outlook.
2. If you are sending a message in HTML format, then remember to also specify <meta ... charset=gb2312 ">
3. If you want to use it for mass mailing, remember to modify the Include file function, such as:
Require ("phpmailer/class.phpmailer.php");
To
Require_once ("phpmailer/class.phpmailer.php");
Otherwise, a redefinition of the class is generated.
The code is as follows |
Copy Code |
<?php /******************************* * 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: Normal mail authentication does not need to add @ domain name $mail->password = "MailPassword"; & nbsp SMTP password $mail->from = "yourmail@cgsir.com; /Senders Mailbox $mail-> FromName = "cgsir.com Administrator"; //Sender $mail->charset = "GB2312"; This specifies the character set! $mail->encoding = "base64"; $mail->addaddress ($sendto _email, "username"); Recipient mailboxes and Names $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 Message subject $mail->subject = $subject; Message content $mail->body = ' <meta http-equiv= "Content-language" content= "ZH-CN" > <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "> <body> Welcome to <a href= "http://www.111cn.net" >http://www.111cn.net</a> <br/><br/> Thank you for registering as a member of this site! <br/><br/> </body> '; $mail->altbody = "text/html"; if (! $mail->send ()) { echo "message sent incorrectly <p>"; echo "Message error message:". $mail->errorinfo; Exit } else { echo "$user _name Mail sent successfully!<br/>"; } } Parameter description (send to, mail subject, message content, additional information, user name) Smtp_mail (' yourmail@cgsir.com ', ' Welcome to cgsir.com! ', ' NULL ', ' cgsir.com ', ' username '); ?> |
Need to download Phpmailer packages phpmailer-1.73.tar.gz from Open source community: http://phpmailer.sourceforge.net/