Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4247364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:05:51+00:00 2026-05-21T04:05:51+00:00

I am trying to build an automated email that will send attachments based on

  • 0

I am trying to build an automated email that will send attachments based on a variable that contains the relative path to a file using PHPmailer. The file path is stored in a table in MYSQL. I want to fetch the file path for each email sent using a while loop. Anyone ever done this? The emails get sent fine but without the attachments and the following error is printed:

Could not access file: $filepath

The lines of code in question are lines 11, 12 and 27. Thanks for your help.

1

 require("PHPMailer_v5.1 2/class.phpmailer.php");
    2    while ($row = mysqli_fetch_array($result)){
    3    $to = $row['email'];
    4    $first_name = $row['first_name'];
    5    $last_name = $row['last_name'];
    6    $msg = $row['msg'];
    7    $id = $row['id'];
    8
    9    //the code in question -lines 11 and 12:
    10
    11   $filepath= $row['filepath'];
    12    $filename= $row['filename'];
    13
    14  $mailer = new PHPMailer();
    15  $mailer->IsSMTP();
    16  $mailer->Host = 'ssl://smtp.gmail.com:465';
    17  $mailer->SMTPAuth = TRUE;
    18  $mailer->Username = 'xx';  // Sender's gmail address
    19  $mailer->Password = 'xx';  // Sender's gmail password
    20  $mailer->From = 'xx';  // Sender's email address
    21  $mailer->FromName = 'xx'; // This is the from name in the email
    22  $mailer->Body = "$msg";
    23  $mailer->Subject = "$id";
    24  $mailer->AddAddress('xx');  // Recipient
    25
    26   //Applying the variables fetched from the database - can this be done?
    27  $mailer->AddAttachment('$filepath', '$filename');
    28  
    29    if(!$mailer->Send())
    30  //more code...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:05:52+00:00Added an answer on May 21, 2026 at 4:05 am

    27 $mailer->AddAttachment('$filepath', '$filename');
    should be
    27 $mailer->AddAttachment($filepath, $filename);
    otherwise you just pass “$filepath” and “$filename” to AddAtachment, not the actual data behind the variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to incorporate some JavaScript unit testing into my automated build process. Currently
I'm laying the groundwork for an automated build process and am trying to make
I'm trying to automate the build of the project I'm working on. My ultimate
I'm trying to configure NAnt to automate my build process - once I've got
Trying to build a GUI application in Java/Swing. I'm mainly used to painting GUIs
I trying to build and compile my xcodeproj in command line and it is
I'm trying to build a grammar with the following: NUMERIC: INTEGER | FLOAT |
I'm currently trying to build a personal website to create a presence on the
I am trying to build a function in C/C++ to sort an array and
I'm planning to build a web-app to do automated quizzing for some language classes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.