Use pear in PHP to implement mail sending. configure pear in windows

Source: Internet
Author: User
This article mainly introduces how to configure pear in windows. PHP uses pear to enable mail sending. if you are interested, you can refer to the mail function provided by PHP, however, this function does not work properly. you need to configure the email server and does not support smtp verification. I found a code to send emails, but there is always an error. here I use the PEAR Mail class and use smtp to send emails.

First of all, I recommend using the latest version of PHP5, because I encountered a lot of problems with PHP4, mostly because the encapsulated class versions are too high, so it is not compatible with PHP4.
Installation method:
1. double-click the go-pear.bat in the php directory.
2. follow the prompts to enter some configuration information, mainly to ask whether to directly access the Internet or use a proxy. if there is no proxy server, press enter directly.
3. you will be prompted to bind some packages to PHP and select Y.
4. install the basic package and prompt that the installation is successful.
5. open the php. ini file in the windows directory and find the following:
; UNIX: "/path1:/path2"
; Include_path = ".:/php/shortdes"
;
; Windows: "\ path1; \ path2"
; Include_path = ".; c: \ php \ shortdes"

Remove the comment from the last line and change the following path to your PEAR path, for example:
Export de_path = ".; c: \ php \ pear \"
Save PHP. INI and restart APACHE.

Now PEAR is ready. we need to put the classes in the pear folder under the php directory, but there are not many available classes now. we need to download and install them online.

You can find PEAR in your PHP root directory. bat file (this is only available when the above installation is executed), this is the command for managing pear, used in CMD, you need to set the environment variable PATH, or double-click the generated EV_XXX.REG file. Some of its command functions are as follows:
1. security protection:

Install a pear class library from the network:
Pear install packagename

Downloading packages but not worried:
Pear download packagename
Pear download-all

Installed package:
Pear install filename. tgz

2. list:

Currently, the pear class library list is available on the pear website:
Pear remote-list

List installed packages:
Pear list

List packages that can be upgraded:
Pear list-upgrades

3. Update (upgrade ):

Update package:
Pear upgrade packagename
Pear upgrade-all

4. remove:

Remove the installed package:
Pear uninstall packagename

Go to the PHP directory from cmd and run pear install mail.
If the installation process prompts that some libraries are not installed, continue to install these libraries

This continues the installation:

Some information will prompt that the installation is successful. in this case, the pear directory contains an additional mail directory and a mail. php file. this is the file to be referenced later.
Below is the code we use to send emails:

<? Require_once 'mail. php '; flush (); $ conf ['mail'] = array ('host' => 'Mail .nenu.edu.cn', // smtp server address, you can use the IP address or domain name 'auth' => true, // true to indicate that the smtp server needs to be verified, and false code does not require 'username' => 'guanhf844 ', // username 'password' => 'Your password' // password); $ headers ['from'] = 'guanhf844 @ nenu.edu.cn '; // mail address $ headers ['to'] = 'chf007server @ 163.com '; // mail address $ headers ['subobject'] = 'Test mail send by php '; // Mail Title $ mail_object = & Mail: factory ('smtp ', $ Conf ['mail']); $ body =' <MSG hello world !!! MSG '; // email body $ mail_res = $ mail_object-> send ($ headers ['to'], $ headers, $ body); // send if (PEAR :: isError ($ mail_res) {// Check the error die ($ mail_res-> getMessage ();} echo 'send finished. ';?>

The test message is sent successfully, and the speed is quite fast. other mailboxes are not tested.

The above is all the code for PHP to use pear to implement the mail sending function. I hope it will be helpful for your learning.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.