smtp-auth over ssl なsmtpサーバーからメールを送る。
PHP -> 5.4.6
[1] pear-Mail のインストール
cd /usr/ports/mail/pear-Mail
make config-recursive
PEAR_NET_SMTPを有効にする
make
make install
[2] コーディング
1 <?php
2 require_once("Mail.php");
3
4 // require for includeing japanese mail
5 mb_language("Japanese");
6 mb_internal_encoding("UTF-8");
7
8 // settting of smtp servser
9 $params = array(
10 "host" => "ssl://smtp-server-address",
11 "port" => 465,
12 "auth" => true,
13 "username" => "account",
14 "password" => "possword"
15 );
16
17 // make instance of PEAR::Mail
18 $mailObject = Mail::factory("smtp", $params);
19
20 // address of recipients
21 $recipients = "to-address@gmail.com";
22
23 // mail header
24 $header = array(
25 "To" => "to-address@gmail.com",
26 "From" => "from-address@gmail.com",
27 "Subject" => mb_encode_mimeheader("テストメール")
28 );
29
30 // body of mail
31 $body = "これは、テストメールです。";
32
33 // encoding
34 $body = mb_convert_encoding($body, "ISO-2022-JP", "UTF-8");
35
36 // sending
37 print("Sending....<br>");
38 $ret =$mailObject->send($recipients, $header, $body);
39 if(PEAR::isError($ret)){
40 print($ret->getMessage());
41 }
42
43 ?>
[3] PHP E_STRICT について
以下のようなエラーが出る場合
Strict Standards: Non-static method Mail::factory() should not be called statically in
/usr/local/www/apache22/data/pearmail/index.php on line
18Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in
/usr/local/share/pear/Mail/smtp.php on line
365Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in
/usr/local/share/pear/Net/SMTP.php on line
450
これらのエラーは、Fartalなエラーではないため
/usr/local/etc/php.ini のerror_reportingを以下のようにして
error_reporting = E_ALL & ~E_STRICT
E_ALL からE_STRICTを除く設定にする。