gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 23:57:29 24 4
gpt4 key购买 nike

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

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

这是我遇到的错误:

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

最佳答案

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

@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 调用前添加了一个 @

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

关于php - 在 Windows 上使用 php 和 pear 发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8280829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com