search
HomeBackend DevelopmentPHP TutorialPHP uses pear to implement mail sending function. Configure pear in windows environment, pearmail_PHP tutorial

PHP uses pear to implement the mail sending function. Configure pear in the windows environment. pearmail

PHP can use its own mail() function to send emails, but this function is very difficult to use. The mail server needs to be configured, and it does not support smtp authentication, so it cannot work properly on many occasions. I found a code to send emails, but it always goes wrong. I use PEAR's Mail class here and use smtp to send emails.

First install, I recommend using the latest version of PHP5, because I have a lot of problems with PHP4, mostly because the versions of the encapsulated classes are too high and are incompatible with PHP4.
Installation method:
1. Double-click go-pear.bat in the php directory.
2. Enter some setting information according to the prompts, mainly asking whether to access the external network directly or use a proxy. If there is no proxy server, just press Enter. I just press Enter.
3. Then you will be prompted to bind some packages to PHP, select Y.
4. Then install the basic package and prompt that the installation is successful, it’s that simple.
5. Open the php.ini file in the windows directory, and then find the following location:
; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "path1;path2"
;include_path = ".;c:phpincludes"

Remove the comment on the last line, and then change the following path to your PEAR path, for example:
include_path = ".;c:phppear"
Save PHP.INI and then restart APACHE.

Now that PEAR has been installed, the classes we want to use are placed in the pear folder in the php directory, but there are not many classes available now. We need to download and install them online.

You can find the PEAR.bat file in your PHP root directory (you will have this after executing the installation above). This is the command to manage pear. Use it 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. Installation:

Install a pear library from the network:
pear install packagename

Download packages without installing:
pear download packagename
pear download-all

Install the downloaded package:
pear install filename.tgz

2. List:

Currently a list of all available pear libraries 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 installed packages:
pear uninstall packagename

We enter the PHP directory from cmd and execute pear install mail
If the installation process prompts that some libraries are not installed, continue to install these libraries as shown:

This continues the installation:

Some information will appear, and it will prompt that the installation is successful. At this time, there will be an additional mail directory under the pear directory, and there will also be a mail.php, which is the file we will reference later.
Below is the code we use to send the email:

<&#63;
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.';
&#63;>

After testing, it was successfully sent and the speed was quite fast. It was not tested on other mailboxes.

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

Articles you may be interested in:

  • Class for sending emails through SMTP in php, test passed
  • Code for sending emails using SMTP under php
  • The PHPMailer mail class uses smtp.163.com to send emails
  • PHP mail Solution to failure to send emails through Windows SMTP
  • php example of using smtp to send emails that support attachments
  • PHP implements SMTP email sending class that supports SSL connection
  • PHP uses Pear’s own mail class library to send emails
  • PHP uses Pear to send emails (Windows environment)
  • php uses pear_smtp to send emails

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1121289.htmlTechArticlePHP uses pear to implement the mail sending function. In the windows environment, pear is configured. Pearmail PHP can use its own mail to send emails ( ) function, but this function is very difficult to use. You need to configure the mail server, and...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

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

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use