Phpmailer Mail class Mail send

Source: Internet
Author: User
Tags character set require word wrap

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/

Related Article

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.