PHP uses pear to implement mail send feature pear_php tips for configuring in Windows environment

Source: Internet
Author: User
Tags pear

PHP Mail can be used with its own mail () function, but this function is very bad, need to configure the mail server, and does not support SMTP authentication, in many cases does not work properly. I found a code to send an email, but it always goes wrong, and I use the Mail class in pear to send messages using SMTP.

First install, I push Chen to use the latest version of the PHP5, because I use PHP4 appeared a lot of problems, mostly because of those packaged class version is too high, and PHP4 incompatible with the original.
Installation Method:
1. Double-click Go-pear.bat in the PHP directory.
2. According to the prompts to enter a number of settings information, mainly to ask for direct access to the extranet, or with the agent, if no proxy server direct return, I was directly press ENTER.
3. Then you will be prompted with some packages and PHP bindings, select Y.
4. Then install the basic package and prompt installation success, it is so simple.
5. Open the php.ini file in the Windows directory, and then find the following places:
; UNIX: "/path1:/path2"
; include_path = ".:/ Php/includes "
;
; Windows: "\path1;\path2"
; include_path = ".; C:\php\includes "

Remove the comment from the last line and change the path back to your pear path, for example:
include_path = ".; C:\php\pear\ "
Save the php.ini, and then restart Apache.

Now that pear is all right, the classes we're using are placed under the Pear folder in the PHP directory, but there are not many available classes, and we're going to download and install them online.

In your PHP root directory you can find the Pear.bat file (this thing will be installed on top), this is the command to manage pear, use in cmd, set the environment variable path, or double-click the generated ev_xxx. REG file. Some of its commands function as follows:
1. Installation:

To install a Pear class library from the network:
Pear Install PackageName

Download packages but uneasy outfit:
Pear Download PackageName
Pear Download-all

Installation of downloaded package:
Pear Install filename.tgz

2, List:

The list of all available pear classes on the pear site today:
Pear remote-list

List Mounted Package:
Pear List

List the package that can be upgraded:
Pear List-upgrades

3, Update (upgrade):

Update package:
Pear Upgrade PackageName
Pear Upgrade-all

4. Removal:

To delete an installed package:
Pear Uninstall PackageName

We go from cmd to php directory, execute pear install mail
If the installation process prompts some libraries not to be installed, continue installing the libraries as shown:

This continues the installation:

Out some information, will be prompted to install successfully, then the pear directory out of a mail directory, and there is a mail.php, this is the one we will refer to the file.
Below is the code we use to send mail:

?
Require_once ' mail.php ';
Flush ();

$conf [' mail '] = Array (
    ' host '   => ' mail.nenu.edu.cn ',  //smtp server address, can use IP address or domain name
    ' auth '   => True,         //true indicates that the SMTP server requires authentication, the false code does not require
    ' username ' => ' guanhf844 ',      //username 
    ' password ' => ' Your password '        //password '
;


$headers [' from ']  = ' guanhf844@nenu.edu.cn ';       Sending address
$headers [' to ']   = ' chf007server@163.com ';       The delivery address
$headers [' Subject '] = ' test mail send by PHP ';     Message headers
$mail _object = &mail::factory (' smtp ', $conf [' Mail ']);  

$body = ' <<< MSG                    
Hello World!!!
MSG ';
Message body
$mail _res = $mail _object->send ($headers [' to '], $headers, $body);    Send

if (Pear::iserror ($mail _res)) {             //Detect Error
  die ($mail _res->getmessage ());
}
Echo ' Send finished. '
>

After the test sent successfully, the speed is very fast, other mailboxes did not test.

The above is the PHP use pear to implement mail send function of all the code, hope to help everyone's study.

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.