Use Phpmailer for mailing code sharing, Phpmailer mail _php Tutorials

Source: Internet
Author: User

Use Phpmailer to send code sharing, Phpmailer e-mail


Send mail is a common function, LZ today in the project also met, hereby share.

First, go to download Phpmailer

1, Https://github.com/dwqs/PHPMailer

2, http://download.csdn.net/detail/u011043843/8063583

After downloading, unzip the file to the corresponding location of the project directory, introduce class.phpmailer.php and class.smtp.php into the project, see the code: (Unzip the file do not delete, otherwise not)

<?php
Import Necessary
Require ("class.phpmailer.php");
Require ("class.smtp.php");
Date_default_timezone_set (' Asia/shanghai ');//Set time zone East eight zone
$mail = new Phpmailer (); Set up a mail sending class

$address = "15602277510@163.com";
$mail->issmtp (); Send using SMTP mode
$mail->charset = "UTF-8";//Set encoding, otherwise send Chinese garbled
$mail->host = "smtp.qq.com"; Your enterprise Post office domain name
$mail->smtpauth = true; Enable the SMTP authentication feature
$mail->username = "461147874@qq.com"; Post Office User name (please fill in the full email address)
$mail->password = "**********"; Post Office password

$mail->from = "461147874@qq.com"; Email Sender Email Address
$mail->fromname = "Dwqs";
$mail->addaddress ($address, "Dwqs");//recipient address, can be replaced with any email message you want to receive, the format is addaddress ("Recipient Email", "Recipient Name")
$mail->addreplyto ("," "");

$mail->addattachment ("/var/tmp/file.tar.gz"); Add an attachment
$mail->ishtml (TRUE); Set email format to HTML//whether HTML is used

$mail->subject = "Verify Mail"; Message header
$mail->body = "Hello, this is Test mail"; Message content
$mail->altbody = "The body in plain text for non-html mail clients"; Additional information, you can omit

if (! $mail->send ()) {
Echo ' Mailer Error: '. $mail->errorinfo;
} else {
echo "Message sent! Congratulations, Mail sent successfully! ";
}
?>

Test results:


(PHP) using Phpmailer Mail sent successfully, I would like to have the following actions, hope can provide code or ideas

1 first to do a common mailbox login address data
2 According to the user mailbox suffix, determine the user mailbox service provider
3 Web page give a hint, or jump.

Phpmailer How to mass mail? -Technical Questions

After setting the parameters for Phpmailer later, there is one step to add the recipient, right? This assumes that your recipient list is stored in the array $aMails: [PHP] $mail) {???? $oMail->setaddress ($mail);} $oMailer->send ();? >[/php] But here to remind, bulk mail is best to use sendmail way, so as not to send failed. Do not send too many messages at a time to avoid timeouts. It can be sent in batches using paging principle.

http://www.bkjia.com/PHPjc/898293.html www.bkjia.com true http://www.bkjia.com/PHPjc/898293.html techarticle use Phpmailer to implement the message to send the code to share, Phpmailer Mail sends sends the mail is the commonly used function, LZ today also met in the project, hereby share. First, go to download ph ...

  • 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.