PHP uses pear to send mail (Windows environment), Pear Send mail
This article introduces the way PHP uses pear to send mail, and how to install PHP pear under windows, share to everyone for reference, the specific content is as follows
First, pear installation
1, Pear Introduction
Pear is an abbreviation for the PHP extension and application library (the PHP Extension and application Repository). It is a code repository for PHP extensions and applications, in short, pear to php like Cpan (Comprehensive perl Archive Network) to Perl.
The basic goal of pear is to develop into a knowledge base of PHP extensions and library code, and the most ambitious goal of this project is to try to define a standard that will help developers write portable, reusable code.
Installing pear in the WAMP integration environment
1), first download a Go-pear.phar file.
2), go to the PHP run directory installation
I use a WAMP integrated development environment here, the version is wampserver2.2e-php5.4.3-httpd2.2.22-mysql5.5.24-32b, my local installation path is C:\wamp\bin\php\php5.4.3 >
Execute the following command:
Php.exe-d phar.require_hash=0 Go-pear.phar
In this step you can modify the $prefix path of the pear installation, I chose the default, all the way to the installation.
3), modify the Include_path option
Finally pear the default expansion pack is installed, you are prompted whether you need to configure the Include_path option in the php.ini file to point to the installation directory of Pear
Of course you need to configure, otherwise you cannot use, Y and enter, the installation package will automatically modify the Include_path option. The environment variables are not set, so we need to set the environment variables of the system.
Create a new environment variable name, such as
Then add%php_home% to the path variable to complete it.
2. Pear Common Commands
In the command line mode, use the Pear command to install the Pear installation package that you need.
- Pear Help lists all the commands for pear, similar to the Command Assist command for pear.
- Pear Help lists specific information for a pear command
- Pear Help shortcuts list all pear commands in shorthand
Second, installation MAIL,MAIL_MINE,NET_SMTP
- The first step: in the cmd into the PHP running directory, that is, Php.exe.
- Step Two: Install the class library required for sending e-mail using Pear installation mail,pear installed mail_mine,pear installs NET_SMTP
- Step Three: Use Pear list to see if the above three class libraries are installed.
Third, examples
<?php error_reporting (0); PHP will appear non-standard prompts, therefore set require_once "mail.php"; Remember to add the Pear directory to the environment in order to refer to this, or to refer to the absolute path $from = "sender@outlook.com"; Sender $to = "receiver@qq.com"; Receiving party $subject = "hi!"; Subject $body = "Hi,\n\nhow is You"; Content $host = "smtp.live.com"; SMTP Server $port = "587"; Port//$port = "25"; Two ports are $username = "username@outlook.com";//username $password = "password";//password $headers = array (' from ' = $from, ' to ' and ' = ' $to, ' Subject ' + $subject); The message header $SMTP = mail::factory (' SMTP ', Array (' host ' = = $host, ' port ' = = $port, ' auth ' = = true, ' Username ' = $username, ' password ' + $password)); Service Settings//send mail $mail = $smtp->send ($to, $headers, $body); Error handling if (Pear::iserror ($mail)) {echo ("". $mail->getmessage (). "
"); } else {echo ("Message successfully sent!
"); }?>
Iv. how PHP uses the PEAR:NET_SMTP class to send mail
Before using the following source code, configure the path of the pear and download the NET_SMTP package.
Choose a different setup method based on your operating system in the php.ini file:
; UNIX: "/path1:/path2"
include_path = ".:./php/pear"
;
; Windows: "\path1;\path2"
; include_path = ".; C:\php\pear "
Code:
<?phprequire ' net/smtp.php '; $host = ' 126.com ';//smtp server IP or domain name $username= ' arcow ';//Login SMTP server username $password= ' secret ';//Login SMTP server password $from = ' Arcow@126.com '; Who sent the message $rcpt = Array (' test@test.com ', ' arcow@126.com ');//Can be set multiple receivers $SUBJ = "Subject: who you are \ \"//Subject $body = "Test it";//message content/* Build a class */if (! ($smtp = new Net_smtp ($host))) {die ("Cannot initialize class net_smtp!\n");} /* Start connecting to the SMTP server */if (pear::iserror ($e = $smtp->connect ())) {Die ($e->getmessage (). "\ n");} /* SMTP requires authentication */$SMTP->auth ($username, $password, "PLAIN"); /* Set Sender Mailbox */if (Pear::iserror ($smtp->mailfrom ($from))) {Die ("unable to set sender's mailbox to < $from >\n"),}/* Set to receive mail */foreach ($ RCPT as $to) {if (Pear::iserror ($res = $smtp->rcptto ($to))) {Die ("mail cannot be delivered to < $to;:". $res->getmessage (). "\ n");}} /* Start Sending message content */if (Pear::iserror ($smtp->data ($subj. "\ r \ n". $body)) {die ("Unable to send data\n"),}/* Disconnect/* $SMTP->disconnect (); echo "sent successfully! ";? >
This is the way PHP uses pear to send mail, I hope this article is to learn PHP program to help you.
Articles you may be interested in:
- PHP 5.0 Pear Installation Method
- php What is pear?
- PHP Pear Installation and use
- How to troubleshoot errors under Windows installation Pear php5.3.1
- Pear Package Installation method of PHPUnit
- Install pear and phpunit under windows (Note Configuring the PHP command-line environment)
- PHP extension Modules pecl, pear, and Perl differences
- How PHP uses Pear's own mail class library to send mail
http://www.bkjia.com/PHPjc/1088776.html www.bkjia.com true http://www.bkjia.com/PHPjc/1088776.html techarticle PHP uses pear to send mail (Windows environment), Pear Send mail This article describes the way PHP uses pear to send mail, and how to install PHP pear under windows, share to ...