DEV Community

Gcobani Mkontwana
Gcobani Mkontwana

Posted on

failed to open stream: No such file or directory in /home/acifinan/public_html/send-email-attachment.php on line 3

Hi Team

I need help with my phpmailer and i am trying to create send mail with pdf attached on the email but on the server logs its getting this message
PHP Warning: require(.._lib\vendor\phpmailer\phpmailer): failed t`o open stream: No such file or directory in /home/acifinan/public_html/send-email-attachment.php on line 3

require '.._lib\vendor\phpmailer\phpmailer';
use PHPMailer\PHPMailer;

$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!';
}
}
?>

// html code



SELECT A pdf FILE TO UPLOAD


                             <label>ID </label><br>
                            <input type="File" name="id" id="id" accept=".pdf">

                            <br>
                            <label>Bank Statement </label><br>
                            <input type="File" name="bankstatement" id="bankstatement" accept=".pdf">
                            <br>
                            <label>Pay Slip </label><br>
                            <input type="File" name="payslip" id="payslip" accept=".pdf">
                            <br>
                            <input type="Submit" id="btnNow" class="btn apply-btn mt-30" name="button" value="APPLY NOW">
                            </fieldset>`

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

đź‘Ą Ideal for solo developers, teams, and cross-company projects

Learn more