Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a variable for mail attachment path: $mailer->AddAttachment($file_variable);
    primarykey
    data
    text
    <p>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:</p> <p>Could not access file: $filepath</p> <p>The lines of code in question are lines 11, 12 and 27. Thanks for your help.</p> <pre><code>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-&gt;IsSMTP(); 16 $mailer-&gt;Host = 'ssl://smtp.gmail.com:465'; 17 $mailer-&gt;SMTPAuth = TRUE; 18 $mailer-&gt;Username = 'xx'; // Sender's gmail address 19 $mailer-&gt;Password = 'xx'; // Sender's gmail password 20 $mailer-&gt;From = 'xx'; // Sender's email address 21 $mailer-&gt;FromName = 'xx'; // This is the from name in the email 22 $mailer-&gt;Body = "$msg"; 23 $mailer-&gt;Subject = "$id"; 24 $mailer-&gt;AddAddress('xx'); // Recipient 25 26 //Applying the variables fetched from the database - can this be done? 27 $mailer-&gt;AddAttachment('$filepath', '$filename'); 28 29 if(!$mailer-&gt;Send()) 30 //more code... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload