Skip to content
Advertisement

Problem with PHPMailer attaching file (only attaches after page refresh)

I have a script that generates a Certificate upon form submit, as well as sends the generated certificate to the recipients email address. When i enter the details into the HTML form, and submit the form, it fails and comes up with an error saying PHPMailer unable to access the file. But when i click on REFRESH on the browser window, it then succeeds and sends the certificate via email..

My PHPMailer code is below:

JavaScript

The HTML Form to input the data is below:

JavaScript

And finally the script to generate the certificate:

JavaScript

QUESTION:

Why does the PHPMailer only succeed with attaching the file after i have refreshed the page after it first fails?

Advertisement

Answer

I figured it out,

All i had to do was move the PHPMailer script BELOW the scrip that generates and saves the certificate and it worked. So obviously i was calling the mail function before the certificate was saved. so PHPMailer wasn’t able to find the file.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement