大家好,我尝试通过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";
?>
我从here下载phpmail并打开浏览器和http://localhost/mail/
其显示空白页
note: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:4\nStack 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:4\nStack 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:4\nStack trace:\n#0 {main}\n thrown in /var/www/html/lear/index.php on line 4
答案 0 :(得分:0)
首先检查apache错误日志,如果页面上没有错误报告,并调试您的smpt php emailer,请使用以下代码。
echo $email->print_debugger();
这将打印出导致未发送电子邮件的确切错误。
答案 1 :(得分:0)
$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";
}