0

I have a script that runs FPDF that creates and stores a PDF file in a folder.

That works fine.

My question is, am I able to send an email in that same script?

I have attempted it but i always get "Page cannot be displayed"

EDIT I dont want the files attached to the email. I just wish to send a email with some wording thats all.

Wont paste my whole code as its just the end that has the problem:

//display pdf

mkdir("FileBrowser/files/$name", 0777);

$total = count($_FILES['files']['name']);

// Loop through each file
for($i=0; $i<$total; $i++) {
//Get the temp file path
 $tmpFilePath = $_FILES['files']['tmp_name'][$i];

//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
$newFilePath = "FileBrowser/files/$name/" . $_FILES['files']['name'][$i];

//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {

  //Handle other code here

}
}
}


$filename = "FileBrowser/files/$name/$name.pdf";
$pdf->Output($filename, 'F');

require ('PHPMailer/class.phpmailer.php');

$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = '****';                 // Specify main and backup server
$mail->Port = 587;                                    // Set the SMTP port
$mail->SMTPAuth = true;                               

$mail->Username = '****';                // SMTP username
$mail->Password = '****';                  // SMTP password

$mail->From = 'Testing@test.co.za';
$mail->FromName = 'Testing';
$mail->AddAddress('****', 'John Smith');  // Add a recipient

$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}

?>
Str1fe
  • 9
  • 1
  • 4
  • 1
    phpmailer lets you add attachments; go through the documentation and its examples. You'll find it. – Funk Forty Niner Feb 22 '18 at 03:09
  • @FunkFortyNiner i dont wish to add the attachments to the email sir. Just wish to send an email to the admin letting them know a new file has been added. – Str1fe Feb 22 '18 at 06:20
  • The answer to your question is yes. Additionally if you pass in true to the instance of PHPMailer you enable exceptions. That will help you debug your issue. If the Output method is sending headers you most likely want to execute the mail code before that so you can see the errors... – cherrysoft Feb 22 '18 at 11:25
  • make sure PHP error reporting / logging is turned on and search for the underlying error – ADyson Feb 22 '18 at 11:55

0 Answers0