use*_*151 2 php pear mail-mime
我想使用Gmail发送电子邮件.为此,我只运行以下命令
pear install Mail Mail_Mime
Run Code Online (Sandbox Code Playgroud)
我的php文件(filename.php)代码如下
<?php
require_once "Mail.php";
$from = 'from@gmail.com';
$to = 'to@gmail.com';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'from@gmail.com',
'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)
当我使用下面的命令运行这个"filename.php"
php filename.php
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
PHP Warning: include_once(Net/SMTP.php): failed to open stream: No such file or directory in /usr/share/pear/Mail/smtp.php on line 365
PHP Warning: include_once(): Failed opening 'Net/SMTP.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /usr/share/pear/Mail/smtp.php on line 365
PHP Fatal error: Class 'Net_SMTP' not found in /usr/share/pear/Mail/smtp.php on line 366
Run Code Online (Sandbox Code Playgroud)
我正在使用CentOS 7.
use*_*151 10
现在它正在为我工作.我只是使用以下步骤来解决这个问题:
1. pear upgrade --force --alldeps http://pear.php.net/get/PEAR-1.10.1
2. pear clear-cache
3. pear update-channels
4. pear upgrade
5. pear upgrade-all
6. pear install Auth_SASL
7. pear install pear/Net_SMTP
Run Code Online (Sandbox Code Playgroud)
之后一切正常.
感谢大家.