简体   繁体   English

使用pear mail.php包通过gmail smtp发送php表单信息,但出现错误

[英]Sending php form information via gmail smtp using pear mail.php package but I get an error

I am trying to send data from a form to an email. 我正在尝试将数据从表单发送到电子邮件。 I did the following: 我做了以下工作:

  1. Browsed to : http://pear.php.net/package/Mail/download/1.2.0b5 浏览至: http : //pear.php.net/package/Mail/download/1.2.0b5
  2. Downloaded the beta file 1.2.0b5 下载了beta文件1.2.0b5
  3. Unziped the file and placed in XAMPP htdocs folder 解压缩文件并放在XAMPP htdocs文件夹中
  4. Created the following code: 创建了以下代码:
<?php // Pear Mail Library

require_once "Mail.php";
$from = '<johannes.gmail.com>';
$to = '<john.pick@gmail.com>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
        'host' => 'smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'readgreen@gmail.com',
        'password' => 'bon3dfredds'
    ));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<p>Message successfully sent!</p>');
}

?>

but I get the following error: 但我收到以下错误:

Strict Standards: Non-static method Mail::factory() should not be called statically in C:\\xampp\\htdocs\\Mail Tester\\Untitled-1.php on line 22 严格标准:非静态方法Mail :: factory()不应在第22行的C:\\ xampp \\ htdocs \\ Mail Tester \\ Untitled-1.php中被静态调用

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\\xampp\\htdocs\\Mail Tester\\Mail\\smtp.php on line 365 严格的标准:非静态方法PEAR :: isError()不应被静态调用,假设$ this来自C:\\ xampp \\ htdocs \\ Mail Tester \\ Mail \\ smtp.php中不兼容的上下文,位于第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 339 严格标准:非静态方法PEAR :: isError()不应静态调用,假设$ this来自C:\\ xampp \\ php \\ PEAR \\ Net \\ SMTP.php 339行中的不兼容上下文

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 344 Any help will be greatly appreciated 严格的标准:非静态方法PEAR :: isError()不应被静态调用,假设第344行的C:\\ xampp \\ php \\ PEAR \\ Net \\ SMTP.php中的不兼容上下文中的$ this

I had this same exact problem, but i don't think it's an actual problem. 我也有同样的问题,但我不认为这是一个实际的问题。 My code executed just fine. 我的代码执行得很好。 it shouldn't be a problem at all and the errors can be supressed. 完全不应该是一个问题,错误可以被抑制。 The real problem seems to be that the pear Mail module was written for PHP4 and hasn't been updated since 2010. You can see the discussion via the official bug report against the Mail module. 真正的问题似乎是pear Mail模块是为PHP4编写的,自2010年以来未进行过更新。您可以通过针对Mail模块的官方错误报告来查看讨论。 If you would like to, you can update to the the PHP5 friendly Mail2 module that was created to specifically address this problem. 如果愿意,您可以更新为专门解决此问题而创建的PHP5友好Mail2模块

Furthermore, in my code i had to specify the protocol for the server URL. 此外,在我的代码中,我必须指定服务器URL的协议。

'host' => 'smtp.gmail.com'

should become 应该成为

'host' => 'ssl://smtp.gmail.com'

That was the only way I got it to work. 那是我让它起作用的唯一方法。

$host的值应仅为"smtp.gmail.com"

http://pear.php.net/bugs/bug.php?id=19491 http://pear.php.net/bugs/bug.php?id=19491

use link above ,its seems work for me.. 使用上面的链接,似乎对我有用。

Just add static keyword in front of function isError 只需在函数isError前面添加static关键字

in file PEAR.php 在文件PEAR.php中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM