sending mail using php and pear on windows(在 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 发送邮件
- PHP Count 布尔数组中真值的数量 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Laravel 仓库 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01