使用php和梨在Windows上发送邮件 [英] sending mail using php and pear on windows

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

问题描述

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

  require_onceMail.php; 

$ from =onlinebookstorb@gmail.com;
$ to ='$ email';
$ subject =网上书店信息;
$ body =这是您的Id'$ userID'点击< a href = .. / index.php>这里< / a>更改为去网站; // 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'=>
'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()不应静态调用C:\xampp\htdocs\OnlineBookStore\Store\第85行的Register.php



严格标准:非静态方法PEAR :: isError()不应静态调用,假设$ C来自不兼容的上下文C: \\ xampp\php\PEAR\Mail\smtp.php在线365



严格标准:非静态方法PEAR :: isError()不应该称为静态的,假设$这是来自不符合上下文的C:\xampp\php\PEAR\Net\SMTP.php第450行



严格标准:非静态方法PEAR :: isError()不应该静态调用,假设$ this来自不符合上下文的C:\xampp\php\PEAR\Net\SMTP.php第467行



解决方案

我遇到同样的问题,并使用以下方式解决:

  @require_onceMail.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)){

请注意,一个 @ 到所有的梨/邮件呼叫。



我更喜欢这个解决方案来更改一般的错误消息设置,因为我不想看到梨/邮件警告,但我想看到适用于我自己的代码的那些。


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>");
                            }

and this is the errors i am getting :

Strict Standards: Non-static method Mail::factory() should not be called statically in C:\xampp\htdocs\OnlineBookStore\Store\Register.php on line 85

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

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

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\PEAR\Net\SMTP.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)) {

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

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆