[英]how to use php pear mail
如何包含 mail.php 以使用 PHP Pear Mail。 我在 test.php 文件中使用以下代碼:
require_once "Mail.php";
$from = "<test@gmail.com>";
$to = "<testing@gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "<testtest@gmail.com>";
$password = "testtest";
$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>");
}
並且通過此代碼遇到以下錯誤:
Warning: require_once(Mail.php) [function.require-once]: failed to open stream: No such file or directory in D:\Hosting\6525150\html\test.php on line 3
Fatal error: require_once() [function.require]: Failed opening required 'Mail.php' (include_path='.;C:\php5\pear') in D:\Hosting\6525150\html\test.php on line 3
有人可以告訴我有什么問題嗎?
您的錯誤消息是不言自明的。 確保您的機器上安裝了 PEAR::Mail,如果沒有,請安裝它。
Linux:
梨安裝郵件
視窗:
http://www.geeksengine.com/article/install-pear-on-windows.html
如果過程完成。
然后請將您的 Mail.php 包含在您的腳本中(可能在您實例化Mail
對象之前。這應該可以消除您的警告。
包括“/path/to/pear/Mail.php”;
或者
set_include_path("/path/to/pear"); 包括“Mail.php”;
還要確保there is enough permission
給Mail.php
以供 PHP 讀取。
檢查系統中是否安裝了梨。 如果是,則在 php.ini include_path 指令中指定 Pear 安裝目錄的路徑
您需要安裝 PEAR 和 PEAR MAIL 軟件包才能使其正常工作
我從網上拼湊了這些步驟,它有效:
如何安裝 PEAR: 1. Download go-pear.phar at http://pear.php.net/go-pear.phar & save to php directory (eg C:\\Program Files\\PHP\\) 2. Open a command window as administrator, move to your php directory, CMD: php go-pear.phar 3. Accept the default value for everything it asks about; system wide, path options, updating your php.ini etc 4. In php directory double-click PEAR_ENV.reg to update your registry
1. Download go-pear.phar at http://pear.php.net/go-pear.phar & save to php directory (eg C:\\Program Files\\PHP\\) 2. Open a command window as administrator, move to your php directory, CMD: php go-pear.phar 3. Accept the default value for everything it asks about; system wide, path options, updating your php.ini etc 4. In php directory double-click PEAR_ENV.reg to update your registry
然后你需要安裝 PEAR MAIL: 5. CMD: php go-pear.phar 6. CMD: pear install --alldeps mail 7. CMD: pear channel-update pear.php.net
確保在你的電子郵件腳本中有這個: require_once "Mail.php";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.