chr*_*ude 3 php error-handling pear syntax-error
我正在使用PHP 5的PEAR邮件扩展.我在发送邮件时遇到困难,因为它返回了这个错误:Non-static method Mail::factory() should not be called statically.
这是我的代码:
$from = "Stephen <stephen@gmail.com>";
$to = "helper <helperjohn@gmail.com>";
$subject = "Email Test!";
$body = "email test body";
$host = "smtp.nvrforget.com";
$username = "username@nvrforget.com";
$password = "*************";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'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>");
}
Run Code Online (Sandbox Code Playgroud)
我没有收到电子邮件.
如果可以的话,我会使用Swiftmailer,但我的虚拟主机不会让我.
由于PEAR仍然支持PHP4,你可以......
创建要使用的邮件对象,例如
$mail = new Mail;
$smtp = $mail->factory(...
Run Code Online (Sandbox Code Playgroud)
要么
禁用E_STRICT错误
error_reporting(E_ALL ^ E_STRICT);
Run Code Online (Sandbox Code Playgroud)如果你坚持使用PEAR,后者可能更好,因为内部静态调用其他非静态方法.