欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

linux/window配置php PEAR:Mail发送html邮件

程序员文章站 2022-04-18 15:05:29
...

介绍一下linux和windows下 配置 PEAR:Mail,用来 发送 html 邮件 ,做记录备份。 大体上 配置 分为以下几步: 安装pear(高版本的php里已经自带安装pear) pear安装Mail,Mail_Mime,Net_SMTP Yii框架组件代码测试 (一)安装pear (1)Windows系统 本人php

介绍一下linux和windows下配置PEAR:Mail,用来发送html邮件,做记录备份。

大体上配置分为以下几步:

  • 安装pear(高版本的php里已经自带安装pear)
  • pear安装Mail,Mail_Mime,Net_SMTP
  • Yii框架组件代码测试

(一)安装pear

(1)Windows系统

本人php安装路径D:\local\PHPnow\php-5.2.14-Win32,版本5.2.14.

D:\local\PHPnow\php-5.2.14-Win32查看路径下是否有pear.bat,如果没有说明未安装,参考一下步骤。

  1. 下载go-pear,http://pear.php.net/go-pear,并重命名为go-pear.php,放到D:\local\PHPnow\php-5.2.14-Win32目录下;
  2. 打开cmd,cd到D:\local\PHPnow\php-5.2.14-Win32,运行php.exe go-pear.php,根据提示,一路回车直到安装完成;
  3. 双击生成的D:\local\PHPnow\php-5.2.14-Win32目录下的PEAR_ENV.reg,导入相关信息到注册表;
  4. 修改php.ini,include_path,如下:
    ; UNIX: "/path1:/path2"
    ;include_path = ".:/php/includes"
    ;
    ; Windows: "\path1;\path2"
    include_path = ".;D:\local\PHPnow\php-5.2.14-Win32\PEAR"
  5. 重启apache

(2)linux系统

本人测试Red Hat Enterprise Linux Server release 5.4 (Tikanga),php安装路径/usr/local/php,版本5.2.17

首先验证/usr/local/php/bin目录下是否有pear文件,如果有,则说明已经安装。php高版本已经可以自带安装pear,php5.2.17便自带安装。


如果未安装,请参考:


在搭建centreon的过程中,需要pear模块支持。
什么是pear
pear是PHP扩展与应用库(the PHP Extension and Application Repository)的缩写。它是一个PHP扩展及应用的一个代码仓库,简单地说,
pear就是PHP的cpan。
在官网上有说明详细的安装信息,这里作简单说明。
http://pear.php.net/manual/en/about-pear.php
我的PHP目录为/usr/local/php5
在Linux下安装PHP的PEAR:
1)下载
#curl -o go-pear.php  http://pear.php.net/go-pear
如果提示:
PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) ‘json.so’  in Unknown on line 0
Sorry!  Your PHP version is too new (5.2.9) for this go-pear.
Instead use http://pear.php.net/go-pear.phar for a more stable and current
version of go-pear, more suited to your PHP version.
那么要从http://pear.php.net/go-pear.phar获取。
#curl -o go-pear.php http://pear.php.net/go-pear.phar
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100 3594k  100 3594k    0     0   186k      0  0:00:19  0:00:19 –:–:–  196k
会在当前目录下载go-pear.php 页面。
2)运行go-pear.php
# /usr/local/php5/bin/php go-pear.php
3)这里按回车继续安装,CTRL+C放弃安装。
Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type ‘all’ to change all of them or simply press Enter to
accept these locations.
1. Installation base ($prefix)                   : /usr/local/php5
2. Temporary directory for processing            : /tmp/pear/install
3. Temporary directory for downloads             : /tmp/pear/install
4. Binaries directory                            : /usr/local/php5/bin
5. PHP code directory ($php_dir)                 : /usr/local/php5/lib/php
6. Documentation directory                       : /usr/local/php5/docs
7. Data directory                                : /usr/local/php5/data
8. User-modifiable configuration files directory : /usr/local/php5/cfg
9. Public Web Files directory                    : /usr/local/php5/www
10. Tests directory                               : /usr/local/php5/tests
11. Name of configuration file                    : /usr/local/php5/etc/pear.conf
1-11, ‘all’ or Enter to continue:
Beginning install…
Configuration written to /usr/local/php5/etc/pear.conf…
Initialized registry…
Preparing to install…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.7.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.3.0.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.9.4.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.4.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/XML_Util-1.2.1.tar…
install ok: channel://pear.php.net/Archive_Tar-1.3.7
install ok: channel://pear.php.net/Console_Getopt-1.3.0
install ok: channel://pear.php.net/Structures_Graph-1.0.4
install ok: channel://pear.php.net/XML_Util-1.2.1
install ok: channel://pear.php.net/PEAR-1.9.4
PEAR: Optional feature webinstaller available (PEAR’s web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR’s PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR’s PHP-GTK2-based installer)
PEAR: To install optional features use “pear install pear/PEAR#featurename”
** WARNING! Old version found at /usr/local/php5/bin, please remove it or be sure to use the new /usr/local/php5/bin/pear command
The ‘pear’ command is now at your service at /usr/local/php5/bin/pear
** The ‘pear’ command is not currently in your PATH, so you need to
** use ‘/usr/local/php5/bin/pear’ until you have added
** ‘/usr/local/php5/bin’ to your PATH environment variable.
Run it without parameters to see the available actions, try ‘pear list’
to see what packages are installed, or ‘pear help’ for help.
For more information about PEAR, see:
http://pear.php.net/faq.php
http://pear.php.net/manual/
 

重启apache。


(二)pear安装pear安装Mail,Mail_Mime,Net_SMTP

接着用pear安装插件,我们可以在http://pear.php.net/packages.php网站上查看pear可安装的包,为了发送html邮件,我们只需要安装Mail,Mail_Mime,Net_SMTP(Networking)。安装Net_SMTP的时候会自动安装Net_Socket.

安装过程比较简单:

Windows:用cmd执行

D:\local\PHPnow\php-5.2.14-Win32\pear.bat install Mail
D:\local\PHPnow\php-5.2.14-Win32\pear.bat install Mail_Mime
D:\local\PHPnow\php-5.2.14-Win32\pear.bat install Net_SMTP






linux类似:

/usr/local/php/bin/pear install Mail
/usr/local/php/bin/pear install Mail_Mime
/usr/local/php/bin/pear install Net_SMTP


安装完毕重启apache,接下来便是测试了。



(三)Yii框架组件代码测试

先可以参考官网示例:http://pear.php.net/manual/en/package.mail.mail-mime.example.php

 HTML version of email