欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

phpmail類發(fā)送郵件函數(shù)代碼

 更新時間:2012年02月20日 16:13:45   作者:  
前天要給網(wǎng)站做一個小功能,就是在用戶留言的時候發(fā)郵件通知管理員。我們都知道在PHP里有一個mail函數(shù),但是要求服務(wù)器要有郵件服務(wù)器的功能,比如簡單的SMTP或者POP3。但是,如果我們的服務(wù)器沒有這種功能,那么怎么辦呢
有了phpmail這個類,你就不用愁了。這是個外國人寫的一個類,我們就只管“拿來主義”了。下面是基于這個類里面的send()方法寫的一個函數(shù):
復(fù)制代碼 代碼如下:

function send_mail ($title,$content,$from,$to,$charset='gbk',$attachment ='')
{
include '/class/PHPMail.class.php';
header('Content-Type: text/html; charset='.$charset);
$mail = new PHPMailer();
$mail->CharSet = $charset; //設(shè)置采用gb2312中文編碼
$mail->IsSMTP(); //設(shè)置采用SMTP方式發(fā)送郵件
$mail->Host = "smtp.qq.com"; //設(shè)置郵件服務(wù)器的地址
$mail->Port = 25; //設(shè)置郵件服務(wù)器的端口,默認(rèn)為25
$mail->From = $from; //設(shè)置發(fā)件人的郵箱地址
$mail->FromName = ""; //設(shè)置發(fā)件人的姓名
$mail->SMTPAuth = true; //設(shè)置SMTP是否需要密碼驗證,true表示需要
$mail->Username = $from; //設(shè)置發(fā)送郵件的郵箱
$mail->Password = ""; //設(shè)置郵箱的密碼
$mail->Subject = $title; //設(shè)置郵件的標(biāo)題
$mail->AltBody = "text/html"; // optional, comment out and test
$mail->Body = $content; //設(shè)置郵件內(nèi)容
$mail->IsHTML(true); //設(shè)置內(nèi)容是否為html類型
$mail->WordWrap = 50; //設(shè)置每行的字符數(shù)
$mail->AddReplyTo("地址","名字"); //設(shè)置回復(fù)的收件人的地址
$mail->AddAddress($to,"星模實訓(xùn)"); //設(shè)置收件的地址
if ($attachment != '') //設(shè)置附件
{
$mail->AddAttachment($attachment, $attachment);
}
if(!$mail->Send())
{
return false;
} else {
return true;
}
}

一般就是用QQ郵箱了,因為QQ郵箱很容易開啟SMTP和POP3服務(wù),而且免費,注意的就是郵件的內(nèi)容格式和編碼。
PHPMail.class.php這個類,點擊下載吧!

相關(guān)文章

最新評論