我想使用 Gmail 发送电子邮件。为此,我只需运行以下命令
pear install Mail Mail_Mime
我的 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>');
}
?>
当我使用以下命令运行此“filename.php”时
php filename.php
我收到以下错误
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
我正在使用 CentOS 7。