0

hi all i try to send email through phpmail i try this code

<?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";

 ?>

i download phpmail from here and open my browser and http://localhost/mail/ its show blank page

note:os ubuntu and all php and phpmailer inside of mail folder

and i use apache2

this is my error log

[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
  • 1
    And what's happening? – Dominique Jul 26 '18 at 07:15
  • And what are your thoughts on "require(phpmailer/PHPMailerAutoload.php): failed to open stream: **No such file or directory**" ? – mario Jul 26 '18 at 07:21
  • Possible duplicate of [PHPMailer is not working at all](//stackoverflow.com/q/20000869) or [Failed opening required 'PHPMailer-master/PHPMailerAutoload.php' (include\_path='.:/usr/share/pear:/usr/share/php')](//stackoverflow.com/q/37639478) or [PHP require failing to open stream](//stackoverflow.com/q/50817959) – mario Jul 26 '18 at 07:22
  • @mario its in same folder /var/www/html/lear/phpmailer , index.php –  Jul 26 '18 at 07:22
  • what is the location of your phpmailer folder? – piyush Jul 26 '18 at 07:23
  • use the try/catch block to catch exception.. check this answer [link](https://stackoverflow.com/a/2386576/3147302) – Razinal Jul 26 '18 at 07:26
  • You're using a very old version of PHPMailer. Update to the latest version. Base your code on the gmail example provided with PHPMailer, and read the readme which tells you how to load PHPMailer classes with and without composer. Adding a try/catch block will do nothing since you've not enabled exceptions in PHPMailer. – Synchro Jul 28 '18 at 06:39
  • Possible duplicate of [Failed opening required 'PHPMailer-master/PHPMailerAutoload.php' (include\_path='.:/usr/share/pear:/usr/share/php')](https://stackoverflow.com/questions/37639478/failed-opening-required-phpmailer-master-phpmailerautoload-php-include-path) – Synchro Jul 28 '18 at 06:40

2 Answers2

0

First of all check apache error log if there's nothing put error reporting on the page and to debug you smpt php emailer use below code .

 echo $email->print_debugger();

This will print the exact error what causing not sending emails.

piyush
  • 655
  • 4
  • 11
  • where can i check log? and where can i add this line? –  Jul 26 '18 at 07:15
  • 1
    put this line after $mail->send()..........if your are using ubuntu check error log via below command........ tail -f /var/log/apache2/error.log – piyush Jul 26 '18 at 07:16
  • So its that .......phpmailer file path is not correct...you need to provide the correct path of your phpmailer lib. – piyush Jul 26 '18 at 07:21
  • but ins in same folder /var/www/html/lear/phpmailer , index.php –  Jul 26 '18 at 07:25
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176774/discussion-between-piyush-and-sanjan). – piyush Jul 26 '18 at 07:28
  • but i diwnload from here and extract my lear folder https://github.com/PHPMailer/PHPMailer –  Jul 26 '18 at 07:28
  • 1
    there's a command to install it via composer ........composer require phpmailer/phpmailer check this – piyush Jul 26 '18 at 07:36
  • 1
    Please accept it as correct answer if you done and found adequate...... – piyush Jul 26 '18 at 08:03
  • This answer is simply incorrect. PHPMailer does not contain a `print_debugger` method. – Synchro Jul 28 '18 at 06:37
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";
 }
Rohit Guleria
  • 72
  • 1
  • 12