We use phpmailer to implement the Mail sending function. here we also use a template to read the content of a specified file and send it to a friend. & lt ;? Php @ session_start (); include (Dinam
We use phpmailer to implement the Mail sending function. here we also use the template to read the specified file and send it to a friend.
-
- @ Session_start ();
- Include (dirname (_ FILE _). './inc/function. php ');
- Require (dirname (_ FILE _). "/mail/class. phpmailer. php ");
- $ Array = array_unique (Get_value ('mail', 1 ));
- $ Type = Get_value ('type', 1 );
- $ Mail = new PHPMailer ();
- $ Count = 0;
- $ Bad = 0;
- $ Mail-> IsSMTP (); // set mailer to use SMTP
- $ Mail-> Host = "smtp.163.com"; // smtp1.example.com; smtp2.example. comspecify main and backup server
- $ Mail-> SMTPAuth = true; // turn on SMTP authentication
- $ Mail-> Username = "mailangel123"; // SMTP username
- $ Mail-> Password = "******"; // SMTP password
- $ Mail-> From = "mailangel123@163.com ";
- $ Mail-> FromName = "from your friends ";
- $ MailBody = GetContent ($ type );
- // $ Array = explode ('|', $ rs ['mail']);
- Foreach ($ array as $ tmpmail ){
- If (@ preg_match ("/w + ([-+.] w +) * @ w + ([-.] w + )*. w + ([-.] w +) */", $ tmpmail)
- | Strlen ($ User_Mail) <6)
- {
- $ Mail-> AddReplyTo ("mailangel123@163.com", "44 ");
- $ Mail-> AddAddress ($ tmpmail, 'Hello! ');
- $ Mail-> WordWrap = 50;
- $ Mail-> CharSet = "GB2312 ";
- // $ Mail-> AddAttachment ("/var/tmp/file.tar.gz ");
- // $ Mail-> AddAttachment ("/tmp/image.jpg", "new.jpg ");
- $ Mail-> IsHTML (true );
- $ Mail-> Subject = "your friends invite you to take a photo! ";
- $ Mail-> Body = $ MailBody;
- If (! $ Mail-> Send ())
- {
- $ Bad ++;
- $ Mail-> ClearAddresses ();
- $ Mail-> ClearAttachments ();
- }
- Else
- {
- $ Count ++;
- }
- }
- ShowMsg ("result: $ count ");
- }
- The following article reads and sends html documents,
- Function GetContent ($ type ){
- If ($ type)
- {
- If (file_exists ('./mail_room.html '))
- {
- $ Content = file_get_contents ('./mail_room.html ');
- }
- Else
- {
- ShowMsg ('file can 'read fail ');
- }
- }
- Else
- {
- If (file_exists ('./mail_person.html '))
- {
- $ Content = file_get_contents ('./mail_person.html ');
- }
- Else
- {
- ShowMsg ('person file read fail! ');
- }
- }
- Return $ content;
- }
- /* Echo "script" alert ('Sending off ". $ count." email succeeded '); script "; */
- ?>