Skip to content

Instantly share code, notes, and snippets.

@allen501pc
Created December 29, 2011 06:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allen501pc/1532414 to your computer and use it in GitHub Desktop.
Save allen501pc/1532414 to your computer and use it in GitHub Desktop.
PHPMailer 基本範例 (含發送附件檔)
<?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 = "xxx@gmail.com"; //Gmail帳號
$mail->Password = "yourpassword"; //Gmail密碼
$mail->From = "xxx@gmail.com"; //設定寄件者信箱
$mail->FromName = "yourname"; //設定寄件者姓名
$mail->Subject = "title"; //設定郵件標題
$mail->Body = "Mail content"; //設定郵件內容
$mail->IsHTML(true); //設定郵件內容為HTML
$mail->AddAttachment("filename"); // 設定附件檔檔名
$mail->AddAddress("receiver@xxx.com", "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