Created
December 29, 2011 06:41
-
-
Save allen501pc/1532414 to your computer and use it in GitHub Desktop.
PHPMailer 基本範例 (含發送附件檔)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include("class.phpmailer.php"); // 匯入PHPMailer library | |
$mail= new PHPMailer(); //建立新物件 | |
$mail->IsSMTP(); //設定使用SMTP方式寄信 | |
$mail->SMTPAuth = true; //設定SMTP需要驗證 | |
$mail->SMTPSecure = "ssl"; // Gmail的SMTP主機需要使用SSL連線 | |
$mail->Host = "smtp.gmail.com"; //Gamil的SMTP主機 | |
$mail->Port = 465; //Gamil的SMTP主機的SMTP埠位為465埠。 | |
$mail->CharSet = "utf-8"; //設定郵件編碼,預設UTF-8 | |
$mail->Username = "[email protected]"; //Gmail帳號 | |
$mail->Password = "yourpassword"; //Gmail密碼 | |
$mail->From = "[email protected]"; //設定寄件者信箱 | |
$mail->FromName = "yourname"; //設定寄件者姓名 | |
$mail->Subject = "title"; //設定郵件標題 | |
$mail->Body = "Mail content"; //設定郵件內容 | |
$mail->IsHTML(true); //設定郵件內容為HTML | |
$mail->AddAttachment("filename"); // 設定附件檔檔名 | |
$mail->AddAddress("[email protected]", "Receiver"); //設定收件者郵件及名稱 | |
if(!$mail->Send()) { | |
echo "送信失敗: " . $mail->ErrorInfo; | |
} | |
else { | |
echo "送信成功!"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment