背景:
前幾天客戶讓在網站里面增加一個報名的系統,于是就想到了自定義表單,但是后面客戶提出要求說假如學院報名后能把報名信息發送到他的qq郵箱,這樣,他就不用登陸后臺查看dede的自定義表單了。覺得也不錯,比較實用,先前考慮的是dede的會員郵件系統來實現,最后發現沒有這個phpmailer省事。于是利用phpmailer 的class.phpmailer.類實現發送。
修改:/plus/diy.php 修改了自定義表單模板的童鞋記得修改下templets/plus/post_diyform.htm 這模板。 很靈活
實現代碼:
<?php
include_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults tousing php "mail()"
$mail->IsSMTP(); // telling the class touse SMTP
$mail->Host = "smtp.mytianshui.com"; //SMTP server
$mail -> Post = “25”;
$mail->From = "clj@mytianshui.com";
$mail ->password = “*******”;
$mail->FromName = "chen liangji";
$mail->Subject = "Email title ";
$mail ->body =”this is body content ” ; //也可以把自定義表單里面獲得的字段輸出
$mail->AltBody = "To view the message, please use anHTML compatible email viewer!"; // est
$mail->AddAddress("ouranimation0000@qq.com","張晨文");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
這樣,當我們action =post的時候把自定義表單數據提交到了數據庫,并且也會發送到ouranimation0000@qq.com 這個指定的郵箱。
任務完成。