沃梦达 / 编程问答 / php问题 / 正文

在 Windows 上使用 php 和 pear 发送邮件

sending mail using php and pear on windows(在 Windows 上使用 php 和 pear 发送邮件)

本文介绍了在 Windows 上使用 php 和 pear 发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 php 脚本发送电子邮件,但我收到错误这是我的代码.我正在使用 xampp netbeans 和 windows.我在 php.ini 文件中包含了梨,但仍然有错误任何想法

I am trying to send an e-mail using php script but i am getting errors this is my code.i am using xampp netbeans and windows. and i included pear in the php.ini file but still having thies errors any ideas

 require_once "Mail.php";
                            
                            $from = "onlinebookstorb@gmail.com";
                            $to = "'$email'";
                            $subject = "Online book store information";
                            $body = "This is your Id '$userID' click <a href =../index.php > here </a> to change to go to the website "; //todo change URL to make it work when it is online

                            $host = "ssl://smtp.gmail.com";
                            $port = "993";
                            $host = "smtp.gmail.com";
                            $username = "onlinebookstoreb@gmail.com";
                            $password = "";

                            $headers = array('From' => $from,
                                'To' => $to,
                                'Subject' => $subject);
                            $smtp = Mail::factory('smtp', array('host' => $host,
                                        'port' => $port,
                                        'auth' => true,
                                        'username' => $username,
                                        'password' => $password));

                            $mail = $smtp->send($to, $headers, $body);
                            if (PEAR::isError($mail)) {
                                echo("<p>" . $mail->getMessage() . "</p>");
                            } else {
                                echo("<p>Message successfully sent!</p>");
                            }

这是我得到的错误:

严格标准:非静态方法 Mail::factory() 不应在第 85 行的 C:xampphtdocsOnlineBookStoreStoreRegister.php 中静态调用

Strict Standards: Non-static method Mail::factory() should not be called statically in C:xampphtdocsOnlineBookStoreStoreRegister.php on line 85

严格标准:不应静态调用非静态方法 PEAR::isError(),假设 $this 来自第 365 行 C:xamppphpPEARMailsmtp.php 中的不兼容上下文

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:xamppphpPEARMailsmtp.php on line 365

严格标准:不应静态调用非静态方法 PEAR::isError(),假设 $this 来自第 450 行 C:xamppphpPEARNetSMTP.php 中的不兼容上下文

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:xamppphpPEARNetSMTP.php on line 450

严格标准:不应静态调用非静态方法 PEAR::isError(),假设 $this 来自第 467 行 C:xamppphpPEARNetSMTP.php 中的不兼容上下文

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:xamppphpPEARNetSMTP.php on line 467

推荐答案

我刚刚遇到了同样的问题并使用以下方法解决了它:

I just ran into the same problem and solved it using:

@require_once "Mail.php";
...
$smtp = @Mail::factory('smtp', array('host' => $host,
                                        'port' => $port,
                                        'auth' => true,
                                        'username' => $username,
                                        'password' => $password));
$mail = @$smtp->send($to, $headers, $body);
if (@PEAR::isError($mail)) {

请注意,我在所有 pear/mail 调用前添加了 @.

Notice that I prepended an @ to all pear / mail calls.

我更喜欢这种解决方案而不是更改一般错误消息设置,因为我不想看到 pear/mail 警告,但我确实希望看到适用于我自己代码的那些.

I prefer this solution to changing the general error message settings as I don't want to see the pear / mail warnings but I do want to see the ones that apply to my own code.

这篇关于在 Windows 上使用 php 和 pear 发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 Windows 上使用 php 和 pear 发送邮件

基础教程推荐