phpmailer郵件發送

<?php
/**
* by www.phpddt.com
*/
header("content-type:text/html;charset=utf-8");
ini_set("magic_quotes_runtime",0);
require 'class.phpmailer.php';
try {
    $to = "[email protected]";
    $from = "[email protected]";
    $username = "1303110";
    $mail = new PHPMailer(true); 
    $mail->IsSMTP();
    $mail->CharSet='UTF-8'; //設置郵件的字符編碼,這很重要,不然中文亂碼
    // $mail->CharSet = 'gbk';
    $mail->SMTPAuth   = true;                  //開啓認證
    $mail->Port       = 465;               
    $mail->SMTPSecure = 'ssl';
    $mail->Host       = "smtp.qq.com"; 
    $mail->Username   = $username;    
    $mail->Password   = "";//***授權碼而不是郵箱密碼***            
    //$mail->IsSendmail(); //如果沒有sendmail組件就註釋掉,否則出現“Could  not execute: /var/qmail/bin/sendmail ”的錯誤提示
    $mail->AddReplyTo($from,"mckee");//回覆地址
    $mail->From       = $from;
    $mail->FromName   = $username;

    $mail->AddAddress($to);
    $mail->Subject  = "phpmailer測試標題";
    $mail->Body = "<h1>phpmail演示</h1>這是php點點通(<font color=red>www.phpddt.com</font>)對phpmailer的測試內容";
    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; //當郵件不支持html時備用顯示,可以省略
    $mail->WordWrap   = 80; // 設置每行字符串的長度
    $mail->SMTPDebug = true;
    //$mail->AddAttachment("f:/test.png");  //可以添加附件
    $mail->IsHTML(true); 
    $mail->Send();
    echo '郵件已發送';
} catch (phpmailerException $e) {
    echo "郵件發送失敗:".$e->errorMessage();
}
?>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章