phpmailer电子邮件发送不起作用



大家好,我尝试通过phpmail发送电子邮件,我尝试了这个代码

<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
//$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'marksman283@gmail.com';
$mail->Password = 'mypassword';
$mail->setFrom('senaidbacinovic@gmail.com', 'Senaid Bacinovic');
$mail->addAddress('jpirakas007@gmail.com');
$mail->Subject = 'SMTP email test';
$mail->Body = 'this is some body';
if ($mail->send())
echo "Mail sent";
?>

我从这里下载phpmail并打开浏览器和http://localhost/mail/显示空白页

注意:os-ubuntu和邮件文件夹内的所有php和phpmailer

我用的是apache2

这是我的错误日志

[Thu Jul 26 12:35:37.405468 2018] [php7:error] [pid 1922] [client 127.0.0.1:40440] PHP Fatal error:  require(): Failed opening required 'phpmailer/PHPMailerAutoload.php' (include_path='.:/usr/share/php') in /var/www/html/lear/index.php on line 2
[Thu Jul 26 12:36:31.746585 2018] [php7:warn] [pid 1924] [client 127.0.0.1:40528] PHP Warning:  require(phpmailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in /var/www/html/lear/index.php on line 2
[Thu Jul 26 12:36:31.746643 2018] [php7:error] [pid 1924] [client 127.0.0.1:40528] PHP Fatal error:  require(): Failed opening required 'phpmailer/PHPMailerAutoload.php' (include_path='.:/usr/share/php') in /var/www/html/lear/index.php on line 2
[Thu Jul 26 12:43:53.780141 2018] [php7:error] [pid 1921] [client 127.0.0.1:40950] PHP Fatal error:  Uncaught Error: Class 'PHPMailer' not found in /var/www/html/lear/index.php:4nStack trace:n#0 {main}n  thrown in /var/www/html/lear/index.php on line 4
[Thu Jul 26 12:43:57.170161 2018] [php7:error] [pid 1923] [client 127.0.0.1:40952] PHP Fatal error:  Uncaught Error: Class 'PHPMailer' not found in /var/www/html/lear/index.php:4nStack trace:n#0 {main}n  thrown in /var/www/html/lear/index.php on line 4
[Thu Jul 26 12:44:44.728442 2018] [php7:error] [pid 3665] [client 127.0.0.1:40958] PHP Fatal error:  Uncaught Error: Class 'PHPMailer' not found in /var/www/html/lear/index.php:4nStack trace:n#0 {main}n  thrown in /var/www/html/lear/index.php on line 4
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "email@gmail.com";
$mail->Password = "password";
$mail->SetFrom("example@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("email@gmail.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}

首先,如果页面上没有任何错误报告,请检查apache错误日志,并使用以下代码调试smpt.php电子邮件。

echo $email->print_debugger();

这将打印导致不发送电子邮件的确切错误。

最新更新