【发布时间】:2017-10-26 20:11:02
【问题描述】:
我正在尝试通过 PHP Pear Mail 包发送邮件,我这里有 2 个场景,在第一个场景中邮件发送正确,没有任何错误,但在第二个场景中我收到错误消息。
场景 1:
文件名:testmail.php
<?php
require_once "Mail.php";
$from = "erp@askspidy.com";
$to = "support@askspidy.com";
$subject = "Landing Page Enquiry From -";
$body = "Hello just testing";
$host = "ssl://mail.askspidy.com";
$port = "465";
$username = "support@askspidy.com";
$password = "askspidy@1234";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject,
'MIME-Version' => 1,
'Content-type' => 'text/html;charset=iso-8859-1'
);
$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>");
}
?>
如果我直接在 url 中运行文件,那么邮件发送没有任何错误。
场景 2: 文件名:sendmail.php
<?php
function send_mail($subject,$body)
{
require_once "Mail.php";
$from = "erp@askspidy.com";
$to = "support@askspidy.com";
$host = "ssl://mail.askspidy.com";
$port = "465";
$username = "support@askspidy.com";
$password = "askspidy@1234";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject,
'MIME-Version' => 1,
'Content-type' => 'text/html;charset=iso-8859-1'
);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
}
?>
现在我从不同的文件中调用这个 send_mail 函数
文件名:service/process.php
<?php
require_once("../sendmail.php");
$subject="Landing page enquiry";
$email_body="Hello Just Testing! ";
send_mail($subject,$email_body);
?>
当这个文件在浏览器中执行时,我在线收到错误消息
send_mail($subject,$email_body);
错误:
Warning: include_once(Net/SMTP.php): failed to open stream: No such file or directory in /usr/local/lib/php/Mail/smtp.php on line 348
Warning: include_once(): Failed opening 'Net/SMTP.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /usr/local/lib/php/Mail/smtp.php on line 348
Fatal error: Class 'Net_SMTP' not found in /usr/local/lib/php/Mail/smtp.php on line 349
在场景 1 中一切正常,那么为什么在场景 2 中我收到此错误,我猜路径有问题,但我不确定路径应该是什么以及我应该在哪里包含它。
文件夹结构:
在文件 Mail/smtp.php 中包含代码
require_once "Net/SMTP.php";
注意:我在 Cpanel 账户中手动安装了 PEAR 包,并没有在 php.ini 文件中进行任何设置
【问题讨论】:
标签: php email phpmailer pear require-once