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 am trying to set up an automated build system on Windows using Cygwin.
I am trying to setup an end-of-day automated email using a CRON job. I
I'm trying to setup an automated build server for my rails projects using Hudson
Im trying to build and automated log in using Googles authSub, but I need
I'm trying to work out an automated Build-Deploy-Test workflow using Lab Management/VS 2010 and
I am trying to setup an automated build of my Windows CE application. However,
I'm trying to automate the build of a project in Delphi 2009. I'm using
I'm trying to automate the build process for engineering group. As part of that
I'm trying to build a feature into my framework wrapper that automates registering template
They don't have setMnemonic(), as Buttons do. I'm trying to build some automated UI

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.