PHP uses pear to implement mail sending. in windows, configure pear and pearmail_PHP. tutorial

Source: Internet
Author: User
PHP uses pear to implement the mail sending function. in windows, configure pear and pearmail. PHP uses pear to implement the mail sending function. in windows, pear can be configured. pearmailPHP can use its built-in mail () function to send mails. However, this function is not easy to use and requires configuring the mail server, in addition, PHP uses pear to implement mail sending. in windows, pear and pearmail are configured.

PHP mail can use its built-in mail () function, but this function is not easy to use. you need to configure the mail server and it does not support smtp verification. in many cases, it cannot work normally. 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.

Articles you may be interested in:
  • Php class sent via smtp, test passed
  • Code for sending mails via SMTP in php
  • PHPMailer mail class using smtp.163.com to send mail method
  • Solution for failing to send mail via SMTP in Windows through PHP mail
  • Example of emails that support attachments sent using smtp in php
  • SMTP mail sending class that supports SSL connections in PHP
  • PHP mail method using the mail class library provided by pear
  • PHP uses Pear to send emails (in Windows)
  • Php uses pear_smtp to send emails

When configuring pear in windows, pearmail PHP can use its built-in mail () function, but this function is not easy to use. you need to configure the mail server and...

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.