DEV Community

Gcobani Mkontwana
Gcobani Mkontwana

Posted on

Fatal error: require(): Failed opening required 'public_html/PHPMailer/vendor.autoload.php'

Hi Team

I need some help, i am receiving email but my main object is to get an attachment when a user apply for a loan as pdf. Currently i am unable to achieve this it has been close to a week now with no luck at all including wide research.

// logic
`use PHPMailer\PHPMailer;

require 'public_html/PHPMailer/vendor.autoload.php'; // complaining here about this path(it is like this on the path server though

$msg = '';
if (array_key_exists('bankstatement', $_FILES)) {
//Create a message
$mail = new PHPMailer();
$mail->setFrom('info@acifinance', 'ACI Finance');
$mail->addAddress('gcobani.mkontwana@agilelimitless.org.za', 'ACI Finance');
$mail->Subject = 'ACI Finance Application Loan';
$mail->Body = 'My message body';
//Attach multiple files one by one
for ($ct = 0, $ctMax = count($_FILES['bankstatement']['tmp_name']); $ct < $ctMax; $ct++) {
//Extract an extension from the provided filename
$ext = PHPMailer::mb_pathinfo($_FILES['bankstatement']['name'][$ct], PATHINFO_EXTENSION);
//Define a safe location to move the uploaded file to, preserving the extension
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['bankstatement']['name'][$ct])) . '.' . $ext;
$filename = $_FILES['bankstatement']['name'][$ct];
if (move_uploaded_file($_FILES['bankstatement']['tmp_name'][$ct], $uploadfile)) {
if (!$mail->addAttachment($uploadfile, $filename)) {
$msg .= 'Failed to attach file ' . $filename;
}
} else {
$msg .= 'Failed to move file to ' . $uploadfile;
}
}
if (!$mail->send()) {
$msg .= 'Mailer Error: ' . $mail->ErrorInfo;
} else {
$msg .= 'Message sent!';
}
}
?>`

Top comments (0)