PHPMailer email sending

Source: Internet
Author: User
Tags word wrap

In this mail sending function, we use an open-source mail class outside China. The PHPMailer mail class that everyone can use is very simple. Let's take a simple tutorial today, if you have any need, you can refer to it and give me comments like other attachments.

Note:
1. Set the character set of the email, $ mail-> CharSet = "GB2312"; // specify the character set here! Here I only specify it as GB2312 because Outlook can display the mail subject normally, I tried to set it to UTF-8 but garbled characters are displayed in Outlook.
2. If you are sending an html-format email, remember to specify <meta... charset = GB2312 ">
3. If you want to use it for mass mailing, remember to modify the include file function, such:
Require ("phpmailer/class. phpmailer. php ");
Change
Require_once ("phpmailer/class. phpmailer. php ");
Otherwise, the class will be redefined.

 

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: @ domain name is not required for normal mail authentication.
$ Mail-> Password = "mailPassword"; // SMTP password
$ Mail-> From = "yourmail@cgsir.com"; // sender's mailbox
$ Mail-> FromName = "cgsir.com administrator"; // sender

$ Mail-> CharSet = "GB2312"; // the character set is specified here!
$ Mail-> Encoding = "base64 ";
$ Mail-> AddAddress ($ sendto_email, "username"); // recipient's email address 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 ='
<Html> <Meta http-equiv = "Content-Language" content = "zh-cn">
<Meta http-equiv = "Content-Type" content = "text/html; charset = GB2312">
</Head>
<Body>
Welcome to <a href = "http://www.hzhuti.com"> http://www.bKjia. c0m </a> <br/>
Thank you for registering as a member of this site! <Br/>
</Body>
</Html>
';
$ Mail-> AltBody = "text/html ";
If (! $ Mail-> Send ())
{
Echo "email sending error <p> ";
Echo "email error message:". $ mail-> ErrorInfo;
Exit;
}
Else {
Echo "$ user_name email sent successfully! <Br/> ";
}
}
// Parameter description (sent to, subject, content, additional information, user name)
Smtp_mail ('yourmail @ cgsir.com ',' Welcome to cgsir.com! ', 'Null', 'cgsir. com', 'username ');
?>

Download phpmailerfile package phpmailer-1.73.tar.gz from open source community: http://phpmailer.sourceforge.net/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.