我試圖通過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