xai1981's blog

http://twitter.com/xai1981

PEAR PEAR::Mail インストール

PEAR のインストール

[root@kabosu /etc/httpd/conf]# yum install php-pear
==============================================================
 Package             Arch    Version        Repository   Size
==============================================================
Installing:
 php-pear            noarch  1:1.9.4-4.el6  base        393 k

Transaction Summary
==============================================================
Complete!

(一部省略)

PEAR::Mail のインストール

[root@kabosu /etc/httpd/conf]# pear install -a Mail
WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to update
WARNING: "pear/Auth_SASL" is deprecated in favor of "pear/Auth_SASL2"
downloading Mail-1.2.0.tgz ...
Starting to download Mail-1.2.0.tgz (23,214 bytes)
........done: 23,214 bytes
downloading Net_SMTP-1.6.2.tgz ...
Starting to download Net_SMTP-1.6.2.tgz (13,077 bytes)
...done: 13,077 bytes
downloading Net_Socket-1.0.14.tgz ...
Starting to download Net_Socket-1.0.14.tgz (5,600 bytes)
...done: 5,600 bytes
downloading Auth_SASL-1.0.6.tgz ...
Starting to download Auth_SASL-1.0.6.tgz (9,119 bytes)
...done: 9,119 bytes
install ok: channel://pear.php.net/Mail-1.2.0
install ok: channel://pear.php.net/Net_Socket-1.0.14
install ok: channel://pear.php.net/Auth_SASL-1.0.6
install ok: channel://pear.php.net/Net_SMTP-1.6.2

警告が出た ...

インストールした PEAR::Mail を確認
[root@kabosu /etc/httpd/conf]# pear list Mail
Installed Files For Mail
========================
Type Install Path
php  /usr/share/pear/Mail/mail.php
php  /usr/share/pear/Mail/mock.php
php  /usr/share/pear/Mail/null.php
php  /usr/share/pear/Mail/RFC822.php
php  /usr/share/pear/Mail/sendmail.php
php  /usr/share/pear/Mail/smtp.php
php  /usr/share/pear/Mail/smtpmx.php
test /usr/share/pear/test/Mail/tests/9137.phpt
test /usr/share/pear/test/Mail/tests/9137_2.phpt
test /usr/share/pear/test/Mail/tests/13659.phpt
test /usr/share/pear/test/Mail/tests/rfc822.phpt
test /usr/share/pear/test/Mail/tests/smtp_error.phpt
test /usr/share/pear/test/Mail/tests/validateQuotedString.php
php  /usr/share/pear/Mail.php
php.ini の include_path に PEAR モジュールをのパスを追加
[root@kabosu /etc]# diff -u _php.ini php.ini 
--- _php.ini    2013-11-21 15:29:10.472840446 +0900
+++ php.ini     2013-11-21 15:27:56.181843828 +0900
@@ -789,6 +789,7 @@
 ;
 ; PHP's default setting for include_path is ".;/path/to/php/pear"
 ; http://www.php.net/manual/en/ini.core.php#ini.include-path
+include_path = ".:/php/includes:/user/share/pear"
 
 ; The root of the PHP pages, used only if nonempty.
 ; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root

Apache リスタート後に Program でメールの送信をテストします。

[root@kabosu /var/www/html]# cat mail.php 
<?php
        require_once("Mail.php");
        $mail = Mail::factory("sendmail");
        $header = array(
                'To' => "hoge@foofoo.com",
                'From' => "bar@foofoo.com",
                'Subject' => "Subject"
        );
        $body = "mail body";
        $result = $mail->send("hoge@foofoo.com", $header, $body);
?>
[root@kabosu /var/www/html]# php mail.php

動かない。。。泣きそうなって調べてみたら pear のパスが違ってました。

[root@kabosu /etc]# diff -u _php.ini php.ini 
--- _php.ini    2013-11-21 15:29:10.472840446 +0900
+++ php.ini     2013-11-21 16:37:45.048840774 +0900
@@ -789,6 +789,7 @@
 ;
 ; PHP's default setting for include_path is ".;/path/to/php/pear"
 ; http://www.php.net/manual/en/ini.core.php#ini.include-path
+include_path = ".:/php/includes:/usr/share/pear"
 
 ; The root of the PHP pages, used only if nonempty.
 ; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root

正しい diff はこれ!!無事、メールが送信できました。

参考URL