Re: [請益] 如何將表單加上gmail smtp 自己送出表댠…

看板PHP作者 (寶貝豬)時間15年前 (2009/05/21 17:38), 編輯推噓4(405)
留言9則, 5人參與, 最新討論串1/1
最近搞定了gmail smtp寄信, 假設是在wamp環境下: 1 使用 PHPMailer, 這在google上可以找到教學網頁, 以下擇要列舉幾個 關鍵的設定: 程式中新增 PHPMailer物件後, 以下五個資料參數應該是照著設,無需改變. $mail = new PPHMailer(); $mail->IsSMTP(); $mail->Host = "smtp.gmail.com"; $mail->SMTPSecure = "ssl"; $mail->Port = 465; $mail->SMTPAuth = true; // turn on SMTP authentication 還有 Username 及 Password 就因人而異了. 2 由於gmail的smtp是跑ssl協定, 所以: 2.1 php.ini 設定中要打開 extension=php_openssl.dll 2.2 php\ext目錄下要有 php_openssl.dll 以上設定問題搞定, 接著就是表單內容傳進來, 套入要寄信的html樣板後發信 即可. 以下是個phpMailer寄信的範例. 至於寄信者, 收信名單, 標題, 內容, 就由 程式的其它部份或是表單來決定: <?php require_once("includes/PHPMailer/class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "smtp.gmail.com"; $mail->SMTPSecure = "ssl"; $mail->Port = 465; $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = '你的帳號'; $mail->Password = '你的密碼'; // SMTP password $mail->CharSet = "big5"; //假設要寄big5編碼的內容 $mail->IsHTML(true); //html格式 $mail->From = '你的寄信email信箱'; //寄件人 $mail->FromName = '你的稱呼'; $mail_list=array( array('name'=>'掐力','email'=>'chaxxxe@mxxl.unixxx.cxm'), array('name'=>'香蕉王','email'=>'banxxxking@mxxl.unixxx.cxm') ); //收件名單 //加入收信列 foreach($mail_list as $reader){ $mail->AddAddress($reader['email'], $reader['name']); } $mail->WordWrap = 80; //80個字自動捲行. 設不設沒關係. $mail->Subject = '天大的好消息!'; $mail->Body = '<p>從天上掉下來的禮物</p>'; if(!$mail->Send()){ echo "Mailer Error: " . $mail->ErrorInfo; exit; } echo 'ok'; ?> ※ 引述《a777starmy (7星)》之銘言: : 我花幾天搞好我的表單了 : 現在卡在表單無法在按下「送出」後 : 直接將資料e-mail到我指定的信箱 : 我知道這個有關php smtp ,大概懂一點,但非專業,似懂非懂 : 如果要透過gmail smtp 將表單資料寄到指定的e-mail : 還需要額外加什麼東西呢??不知可否詳細講一下,目前對這方面沒有慧根!! : 如果有推薦書籍,可否推薦一下是哪本書籍呢? : 因為我有去借了一本php的書,但裡面提到的表單沒教 : 因為我想針對gmail 的smtp 弄表單就好了 : 我製作表單的網站: : http://tinyurl.com/qxfusl -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.104.190.247

05/22 13:45, , 1F
這種subject: ... 你打算寄廣告信 ?
05/22 13:45, 1F

05/22 14:00, , 2F
嘿嘿~ 舉例, 舉例咩~
05/22 14:00, 2F

05/22 14:22, , 3F
同事用 PEAR,我順便就發現這個函式庫還真精美..只是
05/22 14:22, 3F

05/22 14:22, , 4F
還搞不懂它包裝的必要;就好像 SDK 指令如果好用,就會
05/22 14:22, 4F

05/22 14:23, , 5F
想直接用.bool mail ( string $to, string $subject,
05/22 14:23, 5F

05/22 14:23, , 6F
這個底層好像也很明白呀..
05/22 14:23, 6F

05/22 14:24, , 7F
沒事,漏看 'gmail'
05/22 14:24, 7F

05/22 14:26, , 8F
謝好分享Orz
05/22 14:26, 8F

09/10 16:14, , 9F
感謝你詳細地說明
09/10 16:14, 9F
文章代碼(AID): #1A5I4QZ- (PHP)