Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn the thinkphp email password retrieval function and send emails to the registered user group.
Qq mail can be used as the sending email address. It can be used to send QQ mail or 163 email addresses. An error message can be returned if the email address does not exist or is incorrect.
Test Platform: php5.3 thinkphp3.2.3
Integrated on the basis of mail sending, the password retrieval function can prevent tampering with the URL, and the URL is valid for 30 minutes, which can be modified by yourself
Package and download (including the complete thinkphp3.2.3). Modify the corresponding database configuration to run
Test Platform php5.4 thinkphp3.2.3 QQ mailbox, 163 mailbox, need to enable IMAP/SMTP service, POP3/SMTP Service
An error message can be returned in the wrong email address.
Put the Email class in \ test \ ThinkPHP \ Library \ Com \ Email
Database Configuration \ test \ Application \ Home \ Conf
The sending function \ test \ Application \ Common \ function. php modifies the content of Lines 14 and 15.
Function. php: The namespace import class cannot inherit the Exception class and an error is returned.
Controller modification \ test \ Application \ Home \ Controller \ EmailController. class. php line 41st
Password retrieval: http://test.com/index.php/Home/Email/
Mass mail: http://test.com/index.php/Home/Bigemail/
The table structure is in the test file.
Function send_mail ($ title, $ content, $ from, $ to, $ chart = 'utf-8', $ attachment = ''){
$ Mail = new PHPMailer ();
$ Mail-> CharSet = $ chart; // sets the gb2312 Chinese encoding.
$ Mail-> IsSMTP ('smtp '); // you can use smtp to send emails.
$ Mail-> Host = "smtp.qq.com"; // set the email server address
$ Mail-> Port = 25; // set the mail server Port. The default value is 25.
$ Mail-> From = $ from; // you can specify the sender's email address.
$ Mail-> FromName = "sender's name"; // you can specify the sender's name.
$ Mail-> SMTPAuth = true; // set whether password verification is required for SMTP. true indicates that password verification is required.
$ Mail-> Username = "set email address for sending"; // set email address for sending
$ Mail-> Password = "XXXXXXXXXXXXXXXXX"; // set the mailbox Password
$ Mail-> Subject = $ title; // you can specify the mail title.
$ Mail-> AltBody = "text/html"; // optional, comment out and test
$ Mail-> Body = $ content; // you can specify the email content.
$ Mail-> IsHTML (true); // sets whether the content is of the html type.
$ Mail-> WordWrap = 50; // you can specify the number of characters in each line.
$ Mail-> AddReplyTo ("Address", "name"); // you can specify the address of the recipient.
$ Mail-> AddAddress ($ to, ""); // you can specify the recipient address.
If ($ attachment! = ''){
$ Mail-> AddAttachment ($ attachment, $ attachment );
}
If ($ mail-> Send ()){
// $ Status1 = "$ to". 'successfully delivered
';
$ Status = 1;
} Else {
// $ Status2 = "$ to". 'An error occurred while sending the email.
';
$ Status = 0;
}
Return $ status;
}
?>
Test.zip (1.11 MB download: 303 times)
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB