PHP如何發(fā)郵件?
sendMail.php中代碼如下:
<?php include_once './lib/class.phpmailer.php'; class ToolKit { //發(fā)送郵件 public static function mail($to,$subject,$content){ $mail = new PHPMailer();//實(shí)例化phpmailer $address = $to;//接收郵件的郵箱 $mail->IsSMTP(); // 設(shè)置發(fā)送郵件的協(xié)議:SMTP $mail->Host = "email.163.com"; // 發(fā)送郵件的服務(wù)器 $mail->SMTPAuth = true; // 打開SMTP $mail->Username = "xxxx@163.com"; // SMTP賬戶 /*在這里填上發(fā)信的賬戶和密碼*/ $mail->Password = "xxxx"; // SMTP密碼 $mail->From = ""; $mail->FromName = ""; $mail->AddAddress("$address", ""); $mail->CharSet = "UTF-8";//設(shè)置字符集編碼 $mail->Subject = $subject; $mail->Body = $content;//郵件內(nèi)容(可以是HTML郵件) $mail->AltBody = $content; return $mail->Send(); } //產(chǎn)生隨機(jī)字符串(長(zhǎng)度為$len,字母為小寫) public static function random($len){ $baseStr = "abcdefghijklmnopqrstuvwxyz1234567890"; //mt_srand(); $strs=""; for($i=0;$i<$len;$i++){ $strs .= $baseStr[mt_rand(0,strlen($baseStr) - 1)]; } return strtolower($strs); } } mail('xxxx@qq.com','test','test'); ?>
ToolKit::mail('xxxx@qq.com','test','test'); <div class="clear"></div>
PHP怎么學(xué)習(xí)?PHP怎么入門?PHP在哪學(xué)?PHP怎么學(xué)才快?不用擔(dān)心,這里為大家提供了PHP速學(xué)教程(入門到精通),有需要的小伙伴保存下載就能學(xué)習(xí)啦!
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://www.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)