[請益] 透過gmail smtp 發信 使用PEAR Mail套ꔠ…
我是使用PEAR Mail套件
最初使用學校的非認證SMTP去寄都沒問題
不過現在想試試看用Gmail 的 SMTP幫我寄
不過都失敗(都沒收到)
以下是我的程式碼
<body>
<?
include('C:\AppServ\php5\PEAR\Mail.php');
include('C:\AppServ\php5\PEAR\Mail\mime.php');
$text = 'aaaaaaaaaaaaaaaaaaaaabbbbbbbbb';
$html = '略';
$crlf = "\n";
$param['text_charset'] = 'utf-8';
$param['html_charset'] = 'utf-8';
$param['head_charset'] = 'utf-8';
$hdrs = array(
'From' => 'xxxx@xxxx.edu.tw',
'Subject' => '系統資訊',
'Content-type' => 'text/html; charset=utf-8'
);
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get($param);
$hdrs = $mime->headers($hdrs);
$host = "ssl://smtp.gmail.com";
$username = "xxxx@gmail.com";
$password = "xxxx";
$port = "465";
$smtp =& Mail::factory('smtp',array(
'host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password
)
);
$smtp->send('xxxxx@xxxx.edu.tw', $hdrs, $body);
?>
</body>
</html>
看過網路上範例
這樣應該是可行的!!
假如是用PHPMailer的要把 php.ini 裡的extension=php_openssl.dll打開
我也去打開了
可是我始終收不到信...
不知道還有哪裡要改?
感謝高手回答!!
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.45.216.46
→
10/28 22:30, , 1F
10/28 22:30, 1F
→
10/28 22:31, , 2F
10/28 22:31, 2F
→
10/28 22:34, , 3F
10/28 22:34, 3F
→
10/28 22:57, , 4F
10/28 22:57, 4F
感謝三樓提醒,我開了除錯訊息,以下是除錯訊息:
Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect
socket: Unable to find the socket transport "ssl" - did you forget to enable
it when you configured PHP? (code: -1, response: )]
DEBUG: Send: QUIT
port 我465和587都試過了 皆不行
google一下 大多都是沒打開extension=php_openssl.dll
不知道是否我的原因出在PHP版本 我現在是5.2.3 現在嘗試用新的看看......
※ 編輯: jameschen318 來自: 140.119.233.59 (10/29 12:31)