要用這個套件透過 Gmail 寄信的話,需要伺服器啟動 SSL 支援才行
Apache 設定方法:(檔案路徑以 Appserv 的安裝路徑為例)
1、C:\Windows\php.ini 當中搜尋「openssl」,把 extension=php_openssl.dll 的註解取消
2、將 C:\Appserv\php5\ 資料夾內的 ssleay32.dll 和 libeay32.dll 複製到 C:\Windows\system32\ 內
3、重新啟動 Apache
要檢查 SSL 有沒有正常啟動,只要打開 Apache 的 error log 就可以看到了~
error log 會在程式集裡面有捷徑,或者也可以直接從檔案總管開啟開啟
位置在 C:\AppServ\Apache2.2\logs\error.log
檔案太大開不了的話,可以直接刪掉,重開 Apache 時就會自動建立一個新的。
另外如果還是開不了 SSL,可以在 php.ini 當中尋找「extension_dir」
確定目錄是不是正確的,Appserv 目錄位址應該指向 C:\AppServ\php5\ext 才對。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
send_mail( $to_address , $to_name , $subject , $body ); function send_mail( $to_address , $to_name , $subject , $body , $attach = "" ) { //使用phpmailer發送郵件 require ( "phpMailer/class.phpmailer.php" ); $mail = new PHPMailer(); $mail ->IsSMTP(); // set mailer to use SMTP $mail ->CharSet = "utf-8" ; $mail ->Encoding = "base64" ; $mail ->From = "account@domain" ; $mail ->FromName = "account name" ; $mail ->Port = 465; //default is 25, gmail is 465 or 587 $mail ->SMTPAuth = true; $mail ->Username = "account@domain" ; $mail ->Password = "*******" ; $mail ->addAddress( $to_address , $to_name ); $mail ->WordWrap = 50; if (! empty ( $attach )) $mail ->AddAttachment( $attach ); $mail ->IsHTML(false); $mail ->Subject = $subject ; $mail ->Body = $body ; if (! $mail ->Send()) { echo "郵件送出失敗!\r\n" ; echo "錯誤訊息: " . $mail ->ErrorInfo . "\r\n" ; return false; } else { echo ( "寄信 $attach 給 $to_name <$to_address> 完成!\r\n" ); return true; } } |