Recommend a PHP email plugin with attachments

Source: Internet
Author: User
Tags base64 character set php email
The code is as follows Copy Code
Require_once (' include/phpmailer/class.phpmailer.php '); Import Phpmailer Class
$mail = new Phpmailer (); Create an instance
$mail-> charset= ' utf-8 '; Setting the character set
$mail-> setlanguage (' ch ', ' include/phpmailer/language/'); Set the directory where language types and language files are located
$mail-> issmtp (); Send using SMTP method
$mail-> Smtpauth = true; To set whether the server requires SMTP authentication
$mail-> Host = smtp_server; SMTP Host Address
$mail-> Port = smtp_server_port; SMTP Host Port
$mail-> from = Smtp_user_mail; Sender email Address
$mail-> fromname = ' Jasonxu '; The sender's user name in the SMTP host
$mail-> Username = smtp_user_name; Sender's name
$mail-> Password = Smtp_user_pass; The sender's password in the SMTP host
$mail-> Subject = ' test message title '; Message subject
$mail-> altbody = ' text/html '; Set up an alternate display when the message body does not support HTML
$mail-> BODY = ' Test the content of the message ';//the contents of the message are made
$mail-> ishtml (true); Whether it is an HTML message
$mail-> addaddress (' chinajason2008#gmail.com ', ' Jasonxu '); The address and name of the recipient
$mail-> addreplyto (' chinajason2008#gmail.com ', ' Jasonxu '); Address and name replied to when the recipient replies
$mail-> addattachment (' include/id.csv ', ' att.csv ');//attachment path and attachment name
if (! $mail-> Send ())//Send mail
Var_dump ($mail-> errorinfo); To view sent error messages


Note: Phpmailer If you add an attachment, you must specify the suffix of the attachment in the name of the attachment, if you do not specify the attachment suffix, the default attachment suffix will be. txt.
such as $mail-> addattachment (' include/id.csv ', ' att '); the path and attachment name of the attachment
If you add an attachment to the above, you may end up receiving an attachment that is att.txt.
AddAttachment can set the attachment encoding and attachment type, such as the attachment added above can also be set to
$mail-> addattachment (' include/id.csv ', ' att.csv ', ' binary ', ' text/comma-separated-values '); the path and attachment name of the attachment,
There are probably several ways to encode attachments: 8bit, base64, binary, and quoted-printable encodings.

and CSV acceptable MIME Type
· Application/octet-stream
· Text/comma-separated-values (recommended)
· Text/csv
Therefore, the attachment type of the CSV format file can be any of the above three types

The


/*phpmailer is a PHP function package that is used to send e-mail messages. It provides the following features:
*. Specify multiple recipients, CC addresses, dark addresses, and reply addresses when sending mail
*. Support for multiple message encodings include: 8bit,base64,binary and Quoted-printable
*. Support SMTP Authentication
*. Support redundant SMTP servers
*. Supports mail with attachments and HTML-formatted messages
*. Custom Headers
*. Supports embedding pictures in messages
*. Debug Flexible
*. Tested compliant SMTP servers include: Sen Dmail,qmail,postfix,imail,exchange
*. Can be run on any platform
 
Phpmailer is a very powerful PHP send message class, you can set the sending email address, reply address, Mail subject, Rich text content, upload attachment,.....
Official website: http://phpmailer.worxware.com/
Download Address: http://code.google.com/a/apache-extras.org/p/phpmailer/ Downloads/list
*/
 

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.