mailtest.php
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 |
<?php require_once("/usr/share/pear/Mail.php"); mb_language("japanese"); mb_internal_encoding("UTF-8"); $params = array( 'host' => 'tls://smtp.gmail.com', 'port' => 465, 'auth' => true, 'username' => 'アカウント名@gmail.com', 'password' => 'パスワード', 'debug' => false, 'protocol'=>'SMTP_AUTH' ); $headers = array( 'From' => 'example@gmail.com', 'To' => 'target@example.net', 'Subject' => mb_encode_mimeheader(mb_convert_encoding("件名","JIS","UTF-8")) ); $recipients = 'target@example.net'; $body = mb_convert_encoding("メールの内容","JIS","UTF-8"); $smtp = Mail::factory('smtp', $params); $e = $smtp->send($recipients, $headers, $body); if ( PEAR::isError($e) ) echo $e->getMessage() . "\n"; |
上記のスクリプトは587(STARTTLS)では送信できません。 Gmail経由からでしか送信しないので465で良いです。 465, 587? これって何? メールサーバ同士、クライアントでやりとりする時のとりきめ、プロトコル。 587番ポート STA …