PHP使用pear实现mail发送功能 windows环境下配置pear,pearmail
PHP使用pear实现mail发送功能 windows环境下配置pear,pearmail
PHP发邮件可以用其自带mail()函数,但是这个函数很不好使,需要配置邮件服务器,并且不支持smtp验证,在很多场合无法正常的工作. 找了个代码发邮件,但总是出错,我在这里用PEAR的Mail类,使用smtp发邮件.
首先安装,我推陈用最新版的PHP5,因为我用PHP4出现了很多问题,大多是因为那些封装好的类版本太高,与PHP4不兼容的原故吧.
安装方法:
1.在php目录中双击go-pear.bat。
2.按照提示输入一些设置信息,主要是问直接访问外网,还是用代理,若无代理服务器则直接回车,我是直接按回车.
3.然后会提示一些包和PHP绑定,选择Y 。
4.然后安装基本包和提示安装成功,就这么简单。
5.打开windows目录下的php.ini文件,然后查找到如下的地方:
; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"
把最后一行的注释去掉,然后把后面路径改成你的PEAR路径,例如:
include_path = ".;c:\php\pear\"
保存PHP.INI,然后重新启动APACHE即可。
现在PEAR已经安好了,我们要用到的类放在php目录下的pear文件夹下,但是现在没有多少可用的类,我们要去网上下载并安装.
在你的PHP根目录中可以找到PEAR.bat文件(执行上边的安装才会有这个东西),这是管理pear的命令,在CMD中使用,要设置环境变量PATH,或双击生成的EV_XXX.REG文件。它的部分命令功能如下:
1、安裝:
从网络安装一个pear类库:
pear install packagename
下载 packages 但不安裝:
pear download packagename
pear download-all
安裝已下载的package:
pear install filename.tgz
2、列表:
目前pear网站上所有可取得pear类库列表:
pear remote-list
列出已安裝package:
pear list
列出可以升級的package:
pear list-upgrades
3、更新(升級):
更新package:
pear upgrade packagename
pear upgrade-all
4、移除:
刪除已安裝的package:
pear uninstall packagename
我们从cmd进入PHP目录,执行pear install mail
如果安装过程提示某些库没有安装,则继续安装这些库如图:
这继续安装:
出来一些信息,会提示安装成功,这时pear目录下多出来一个mail目录,同时有一个mail.php,这是我们一会要引用的文件.
下边是我们用来发邮件的代码:
<? require_once 'Mail.php'; flush(); $conf['mail'] = array( 'host' => 'mail.nenu.edu.cn', //smtp服务器地址,可以用ip地址或者域名 'auth' => true, //true表示smtp服务器需要验证,false代码不需要 'username' => 'guanhf844', //用户名 'password' => '你的密码' //密码 ); $headers['From'] = 'guanhf844@nenu.edu.cn'; //发信地址 $headers['To'] = 'chf007server@163.com'; //收信地址 $headers['Subject'] = 'test mail send by php'; //邮件标题 $mail_object = &Mail::factory('smtp', $conf['mail']); $body = '<<< MSG hello world!!! MSG'; //邮件正文 $mail_res = $mail_object->send($headers['To'], $headers, $body); //发送 if( PEAR::isError($mail_res) ){ //检测错误 die($mail_res->getMessage()); } echo 'Send finished.'; ?>
经测试发送成功,速度挺快的,别的邮箱没有测试。
以上就是PHP使用pear实现mail发送功能的全部代码,希望对大家的学习有所帮助。
您可能感兴趣的文章:
- php中通过smtp发邮件的类,测试通过
- php下使用SMTP发邮件的代码
- PHPMailer邮件类利用smtp.163.com发送邮件方法
- PHP mail 通过Windows的SMTP发送邮件失败的解决方案
- php使用smtp发送支持附件的邮件示例
- PHP实现支持SSL连接的SMTP邮件发送类
- PHP使用pear自带的mail类库发邮件的方法
- PHP使用Pear发送邮件(Windows环境)
- php使用pear_smtp发送邮件

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.
