PHP發郵件的例子,發郵件當然需要一個客戶端郵箱,今天這個例子是使用QQ免費企業郵箱來做為發郵件的郵箱,
01
02include "PHPMailer/class.phpmailer.php";
03function send_mail($frommail,$tomail,$subject,$body,$ccmail,$bccmail){
04$mail = new PHPMailer();
05$mail->IsSMTP();
06$mail->SMTPDebug;
07$mail->Host = "smtp.qq.com";
08$mail->SMTPAuth = true;
09$mail->Port = 25;
10$mail->Username = "[email protected]";
11$mail->Password = "******";
12$mail->AddReplyTo($frommail, 'tankzhang');
13$mail->AddAddress($tomail);
14$mail->SetFrom($frommail, 'tankzhang');
15$mail->IsHTML(true);
16$mail->Subject = $subject;
17$mail->MsgHTML($body);
18if(!$mail->Send())
19{
20echo "郵件發送失敗.
";
21echo "錯誤原因: " . $mail->ErrorInfo;
22exit;
23}else{
24echo "success";
25}
26}
27?>
調用上邊的函數來發送郵件:
1$result= send_mail("[email protected]","[email protected]","test","test","","");
注:如果沒有QQ免費郵箱的朋友,可以自己去騰訊網站注冊一個,然後添加成員和DNS,如果沒有DNS服務器的話,就添加二個mx記錄,比如使用dnspod。