require(..\_lib\vendor\phpmailer\phpmailer): failed to open stream: No such

the mail() function

Moderators: gesf, Michalio

Post Reply
gcozba2023
New php-forum User
New php-forum User
Posts: 5
Joined: Mon Mar 06, 2023 1:30 am

Hi Team

I have a phpmailer file that send email with attached document, but i now get this weird error. How do i get rid of this error from this path when using phpmailer?

PHP Warning: require(..\_lib\vendor\phpmailer\phpmailer): failed to open stream: No such file or directory in /home/acifinan/public_html/send-email-attachment.php on line 3

// code to send attachment for pdf

Code: Select all

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



$msg = '';
if (array_key_exists('bankstatement', $_FILES)) {
    //Create a message
    $mail = new PHPMailer();
    $mail->setFrom('[email protected]', 'ACI Finance');
    $mail->addAddress('[email protected]', '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 to attached documents as pdf
 <fieldset>
                                SELECT A pdf FILE TO UPLOAD
                                <br>
                                
                                 <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>
User avatar
Michalio
Moderator
Moderator
Posts: 361
Joined: Sun Jul 18, 2021 1:33 pm
Location: Poland

Use slashes instead of backslashes and verify that the path is correct. Try to use realpath function
Free coding lessons: https://php-forum.com/phpforum/viewtopic.php?t=29852
Post Reply