我试图通过PHP邮件包发送邮件,我在这里有两个场景,第一种情况下邮件正常发送没有任何错误,但在第二种情况下我收到错误消息。使用PEAR邮件包发送邮件时发生错误
方案1:
文件名:testmail.php
<?php
require_once "Mail.php";
$from = "[email protected]";
$to = "[email protected]";
$subject = "Landing Page Enquiry From -";
$body = "Hello just testing";
$host = "ssl://mail.askspidy.com";
$port = "465";
$username = "[email protected]";
$password = "[email protected]";
$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 = "[email protected]";
$to = "[email protected]";
$host = "ssl://mail.askspidy.com";
$port = "465";
$username = "[email protected]";
$password = "[email protected]";
$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功能:服务/ 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中我得到这个错误,我认为是有问题的路径,但我不知道应该是什么路径,我应该在哪里包含它。
文件夹结构:
包含在文件邮件代码/ smtp.php
require_once "Net/SMTP.php";
注:我在交友帐户和done已经手动安装PEAR包在php.ini文件中没有设置
我已经尝试过这个,那个不工作 – dollar
你有没有改变你所有的require_once。当你改变这个时,错误信息是什么? –
我在'require_once“home/askspidy/public_html/Mail/Net/SMTP.php中使用了此路径;'' ,我得到相同的错误信息,并为我的情况1我也收到错误信息,如**致命错误:require_once():失败打开所需的'家庭/ askspidy/public_html/Mail/Net/SMTP.php'(include_path ='。/opt/php55/lib/php/php')/ home/saniserv/public_html/Mail/smtp。358行的php ** – dollar