Phpmailer mail class usage tutorial

Source: Internet
Author: User
Tags word wrap

Title: phpmailer mail class usage tutorial
Author: Li Yingjiang
Date: 2006-12-07 17:30:39
Reprinted Please retain the author content: http://www.cgsir.com

Step 1: Download phpmailerfile package phpmailer-1.73.tar.gz from Open SourceCommunity: Http://phpmailer.sourceforge.net/

Step 2: Check whether your server system supports socket, for example, phpinfo ();Sockets

If you do not have this option, note the following:SocketIs part of the PHP extension, and A./configure must be specified during compilation.-- Enable-socketsConfiguration options.

Step 3: extract the file to your web server directory and call the class. Note: The class is included first. phpmailer. PHP, create an object, set parameters, and call member functions. For more information, see the following example.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"> <Body>
Welcome to <a href = "http://www.cgsir.com"> http://www.cgsir.com </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 ');

?>

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 the email is in HTML format, remember to specify it as <meta http-equiv = "Content-Type" content = "text/html; 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.

This article only serves as an example. The actual use depends on your patience. If you find any error in this article, please send a letter to inform: my mailbox is admin@cgsir.com, thank you!

 

 

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.