What am i doing wrong, It works when I hard code it, but when I try get the names from MySql it gives me the finger, cannot access docs OR it sends the mail wth no attachemnts is there a better way or something that I am missing,

Look my code and the things I tried:

$attachment_query = "SELECT document FROM transact WHERE clientid=$clientid AND document IS NOT NULL";
        $result = mysql_query($attachment_query ) or die (mysql_error());

    while ($records = mysql_fetch_array($result)) {

//DATA
        $document = $records['document'];
        $directory = "docs/";
        $myfile = $directory.$document;

        //$mail->AddAttachment("docs/1002920123010124348.pdf", "1002920123010124348.pdf");  
        //$mail->AddAttachment($directory.$document, $document); 
        //$mail->AddAttachment("docs/".$document, $document); 
        //$mail->AddAttachment('docs/'.'$document', '$document');
        $mail->AddStringAttachment($document, $document);

    }

  $mail->Send();

What do I use for doing this: $mail->AddAttachment(MYSQLDATA, MYSQLDATA);

AddStringAttachment adds the file as a string, so you should open it and add the contents. Are you sure there is no easier method you can use, like AddAttachment?

My clients are in MySql each have documemts stored on the web server, their invoices I need to send each month, so when they reuquest the documents, instead of attaching them in outlook manualy I select the client form a table, and click send, this has their email address, and document(s) names that belong to them. I store the pdf documents in folder called docs each has a unique name that is a number, and each user may have one or many documents but not more than 10. anyway I would use something else but all the other code i tried has issues with the PDF, when i recieve it the document cannot open in pdf it says it was encoded wrong ... so stuff that ... lol .. i dont like that code anyway ... need a degree in rocket sceince to grasp read it and im not the brightest light in the packet :D

I found the suloution however, it was two mistakes I made in my code, the code now looks like this and it works PERFECTLY!

//RETRIEVE DOCUMENT NAMES THAT NEED TO BE SENT AS ATTACHMENTS
        $attachment_query = "SELECT document FROM transact WHERE clientid=$clientid AND document <> ''";
        $attachemnt_result = mysql_query($attachment_query ) or die (mysql_error());

    while ($records = mysql_fetch_array($attachemnt_result)) {

//DATA
        $document = $records['document'];
        $directory = "docs/";
        $myfile = $directory.$document;

        $mail->AddAttachment($myfile, $document);

    }

  $mail->Send();

  echo "Message Sent OK</p>\n";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.