I'm trying to send MULTIPLE ATTACHMENTS in a single e-mail from a FreeBSD, PHP, MySql, SwiftMailer configuration. I display a form, listing all PDF Files with checkboxes, file names, and file location (hidden) for a client, Then, when <SUBMIT> is pressed, I am trying to format and send an e-mail by looping through the selected files and attaching them to SwiftMailer message instance. E-Mail "without" attachments works, but can't get the e-mail with attachments to work...

Any assistance will be appreciated. If you can help, I'll send the code along or include in a follow-up Post.

OK, thanks... I'm an OLD guy, learning PHP from scratch, have made some progress, but, still revert back to the old COBOL days.

Code follows, area labelled "BEGIN - Create the Transport" is where message is formatted for sending

<?php
/*====================================
*   File:       email_client_20.php
*   By:         Steve Petruska
*   Date:       4/30/13
*
*   This script *
*=====================================
*/
$module = "email_client_20.php";
date_default_timezone_set("America/Los_Angeles");
$_SERVER['DOCUMENT_ROOT'] .= (substr($_SERVER['DOCUMENT_ROOT'],-1)=='/')?'':'/'; 
include $_SERVER['DOCUMENT_ROOT'] . 'mybkfiles/include/NEW_php-main.inc.php';
include $_SERVER['DOCUMENT_ROOT'] . 'mybkfiles/include/include_database.php';
// ##### Functions ##### //
// ##### Functions ##### //
$userid = $_SESSION['userid'];
$company = $_SESSION['company'];
$office = $_SESSION['office'];
###################   connect to database ##############################
$dbSuccess = false;
$dbConnected = mysql_connect($db['hostname'],$db['username'],$db['password']);

if ($dbConnected) {     
    $dbSelected = mysql_select_db($db['database'],$dbConnected);
    if ($dbSelected) {
        $dbSuccess = true;
    } else {
        echo "MySQL connection FAILED<br /><br />";
    }  // end dbSelected
} else {
    echo "DB connection FAILED<br /><br />";
    echo "<br />host = " . $db['hostname'] ;
    echo "<br />User " .  $db['username'];
    echo "<br />Password = " . $db['password'] ;
    echo "<br />Database = " . $db['database'];
}  // end dbConnected
//  END Secure Connection Script
//   Execute code ONLY if connections were successful   
if ($dbSuccess)  {

        /// Check if SUBMIT is pressed
    $output_form = 'NO';
    $email_subject = "";
    $date_null = "0000-00-00 00:00:00";
    if ( isset($_GET['msg']) ) {
        $message = $_GET['msg'];
    } elseif ( isset($_POST['message']) ) {
        $message = $_POST['message'];
    } else {
        echo "<br />OOPS!!!!   Message number NOT found...";
        echo "<br />Notify your administrator immediately...";
        exit;
    } // end IF

        /// Check if SUBMIT is pressed
    $output_form = 'NO';
    $email_subject = "";
    $date_null = "0000-00-00 00:00:00";
    if ( isset($_POST['submit']) ) { 
        $attachments = array(); 

        if ( sizeof($_POST['selectfile']) ) {
            $output_form = 'NO';
            //print_r_html($_POST['selectfile']);
            $checkbox = $_POST['selectfile'];
            $path_name = $_POST['selectloc'];
            $file_name = $_POST['selectname'];
            print_r_html($checkbox);

            foreach ( $checkbox as $id ) {
                echo "<br />ID = " . $id ;
                $path = $path_name[$id];
    // test for vALID PATH
                echo "<br />path = " . $path_name[$id];
                $name = $file_name[$id];
                echo "<br />name = " . $file_name[$id];
                $file = "Swift_Attachment::fromPath('" . $path . "')->setFilename=('" . $name . "', 'application/pdf'),";
                array_push($attachments, $file);    
            } // end FOREACH
            print_r_html($attachments);
            $output_form = 'NO';
            echo "<br />HERE....";
            //exit;
        } else {
            echo '<p class="error">You did NOT SELECT any FILES to ATTACH to your e_mail';
            $output_form = 'YES';   
        } // end IF     

        //echo "<br />End of Validation ....";
    //exit;
    } else {
        $output_form = 'YES';
    }   // end of IF Submit was pressed
    if ($output_form == 'YES' ) {
        //echo "<br />Display Form here ...";
        //    Get message from maillog table
        $SQLselect = "SELECT ";
        $SQLselect .= "* ";     // <<  attributes
        $SQLselect .= "FROM ";
        $SQLselect .= "maillog ";           //  << table name
        $SQLselect .= "WHERE ";
        $SQLselect .= "email_id = '$message' ";         //  << attribute = $value

        $SQLselect_Query = mysql_query($SQLselect);     
        $row = mysql_fetch_object($SQLselect_Query);
        //print_r_html($row);
        $client = $row->email_client;
        $to = $row->email_to;           //      fieldName = an attribute name
        $from = $row->email_from;
        $cc = $row->email_cc;
        $bcc = $row->email_bcc;
        $subject = $row->email_subject;
        $body = $row->email_body;
        $attach = $row->email_attach;
        $to = unserialize($to);
        $cc = unserialize($cc);
        $bcc = unserialize($bcc);
        //print_r_html($to);
        //print_r_html($cc);
        //print_r_html($bcc);
        //exit;
        include $_SERVER['DOCUMENT_ROOT'] . '/mybkfiles/include/header.php';

        $email_org = "<p align='left'>";
        $email_org .= "<br />TO: ";
        foreach ($to as $value) {
            $email_org .= "<br />" . $value;
        }  // end FOREACH
        $email_org .= "<br />CC: ";
        foreach ($cc as $value) {
            $email_org .= "<br />" . $value;
        }  // end FOREACH
        $email_org .= "<br />BCC: ";
        foreach ($bcc as $value) {
            $email_org .= "<br />" . $value;
        }  // end FOREACH
        $email_org .= "<br />SUBJECT: " . $subject;
        $email_org .= "<br />Your E-Mail Message:<br />" . $body . "</p>";
        echo $email_org;

//  display form here
        $mail_form = "<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'>";
        $mail_form .= "<title>Send E-Mail</title></head>";

        $mail_form .=  "<form action='email_client_20.php' method='post' name='form1' enctype='multipart/form-data' type='text'>";
        $mail_form .=  "<table align='center' width=300px cellspacing=3 cellpadding=3 border=1>";
        $mail_form .=  "<tr><th colspan=2 align='center'> ATTACH SELECTED FILES<br />(Five (5) Files MAXIMUM)</th></tr>";
        //$mail_form .=  "<tr><td></td></tr>";

        $LIKE = " LIKE " . "'%-" . $client . "-%'"; 
        $filesql = "SELECT ";
        $filesql .= "* ";       // <<  attributes
        $filesql .= "FROM ";
        $filesql .= "documents, dochist ";          //  << table name
        $filesql .= "WHERE ";
        $filesql .= "doc_link $LIKE ";          //  << attribute = $value
        $filesql .= "AND ";
        $filesql .= "docrec = doc_id ";
        $filesql .= "ORDER BY doc_mod";
        $filesql_Query = mysql_query($filesql); 
        $count = 0;
        while ($filerow = mysql_fetch_array($filesql_Query, MYSQL_ASSOC)) {
            //print_r_html($filerow);
            $fileloc = $filerow['doc_link'];
            $filename = $filerow['doc_mod'];
            //echo "<br />loc = " . $fileloc;
            //echo "<br />name = " . $filename ;
            //$mail_form .= "<tr><td>" . $fileloc . "</td><td>" . $filename . "</td></tr>";
            //$mail_form .= "<td align='center'><input type='radio' name='send_debt' value='cc' /></td>";
            $mail_form .= "<tr><td align='center'><input type='checkbox' name='selectfile[]' value=" . $count . " /></td>"; 
            $mail_form .= "<td align='left'><input type='text' name='selectname[]' size=30 value='" . $filename . "' />";
            $mail_form .= "<input type='hidden' name='selectloc[]' size=60 value='" . $fileloc . "' /></td></tr>";
            $count++;
        }  // end WHILE

        $mail_form .=  "<tr><td colspan=2 align='center'><input type='submit' name='submit' style='font-weight: bold; background-color:#006400;color:#FFFFFF;' value='Send e-Mail' />";
        $mail_form .=  "<input type='hidden' value='$message' name='message'><input type='hidden' name='clno' value='$client'></td></tr></table></form>";
        $mail_form .=  "</body></html>";
        echo "<br />" . $mail_form;  
    } else {
// SEND EMAIL ROUTINE HERE //
// SEND EMAIL ROUTINE HERE //
// SEND EMAIL ROUTINE HERE //
    $body  = $email_body;
//#   BEGIN - Create the Transport ########################################################################
include $_SERVER['DOCUMENT_ROOT'] . '/mybkfiles/include/include_gmail.php';
$templateURL = 'include/eMailTemplate_10.html';
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
  ->setUsername($gmail_id)
  ->setPassword($gmail_pswd)
;   // end $transport
// Create the Mailer using your created Transport

$mailer = Swift_Mailer::newInstance($transport);

{       //  Start of CREATE Message
// Create the message
$message = Swift_Message::newInstance()
  ->setContentType("text/html")
    // Give the message a subject
  ->setSubject($subject)
    // Give it a body
  ->setBody($body)
    // Set the From address with an associative array
  ->setFrom($gmail_id)
    // Set the Sender address with an associative array
  ->setSender($gmail_id)
    // Set the To addresses with an associative array
  ->setTo($to)
    // Set the cc addresses with an associative array
  ->setcc($cc)
    // Set the Bcc addresses with an associative array
  ->setBcc($bcc)

// And optionally an alternative body
//  ->addPart($body_text, 'text/html')

// Optionally add any attachments
//  ->attach(Swift_Attachment::fromPath('my-document.pdf'))
    ->attach($attachments) ;   // end Message create    
echo "<br />Message =<br />" . $message;
echo "<br />HERE 2 ....";
}   // end of CREATE Message
//#   END - Create the Transport ########################################################################

#######################################################################
//  Process e-mail here // #########################################

$mailsql = "INSERT INTO maillog ( ";
$mailsql .= "email_firm, ";
$mailsql .= "email_client, ";
$mailsql .= "email_user, ";
$mailsql .= "email_from, ";
$mailsql .= "email_to, ";
$mailsql .= "email_cc, ";
$mailsql .= "email_bcc, ";
$mailsql .= "email_subject, ";
$mailsql .= "email_body, ";
$mailsql .= "email_attach, ";
$mailsql .= "email_sent ";
$mailsql .= ") ";
$mailsql .= "VALUES ( ";
$mailsql .= "'$company', ";
$mailsql .= "'$client', ";
$mailsql .= "'$userid', ";
$mailsql .= "'$email_from', ";
    $send_email_to = serialize($to);
$mailsql .= "'$send_email_to', ";
    $send_email_cc = serialize($cc);
$mailsql .= "'$send_email_cc', ";
    $send_email_cc = serialize($bcc);
$mailsql .= "'$send_email_bcc', ";

$mailsql .= "'$subject', ";
$mailsql .= "'$body', ";
$mailsql .= "'$attachyorn', ";
$mailsql .= "'$date_null' ";
$mailsql .= " )";
echo "<br />SQL = " . $mailsql;
if (mysql_query($mailsql))  {
    write_txlog($mailsql);
    $messno = mysql_insert_id();
    echo "<br />ADDed your e-mail to the database - seqno = $messno";
} else {
    echo "<br />FAILED to ADD your e-mail to the database";
    echo "<br />Notify your administrator immediately...";
    exit;
}
echo "<br />Message Number = " . $messno;

#######################################################################
echo "<br />attachyorn = " . $attachyorn ;
////exit;
    if ( $attachyorn == 'no' ) {
        if ( !$mailer->send($message, $failures) ) {
            echo "<br />Notify your administrator immediately...";
            echo "<br />Sending Message FAILED....See below for more info...";
            print_r_html($failures);
            exit;
        } else {
            //  Update email record with date/time stamp 
            $stamp = date("Y-m-d H:i:s", time()) ;
            $mailupdate = "UPDATE maillog ";
            $mailupdate .= "SET email_sent = '$stamp' ";
            $mailupdate .= "WHERE email_id = '$messno' ";
            $mailupdate .= "LIMIT 1";
            echo "<br />SQL = " . $mailupdate;
            if (mysql_query($mailupdate))  {
                write_txlog($mailupdate);
            } else {
                echo "<br />FAILED to UPDATE your e-mail as SENT...";
                echo "<br />Notify your administrator immediately...";
                exit;
            }
            //  Add history record with link to e-mail $messno, stating NO ATTACHMENTS were sent
            //echo "<br />Message was sent....";

            //$casenote = "E-mail sent to client Subject: " . $subject . "<br />";
            //$casenote .= "<a href='email_hist_link.php?msg=$messno'>View Email in NEW TAB</a>";
            $histsql = "INSERT INTO hist ( ";
            $histsql .= "hclient, ";
            $histsql .= "hemp, ";
            $histsql .= "htime, ";
            $histsql .= "hsubject, ";
            $histsql .= "hnote, ";
            $histsql .= "hstamp ) ";
            $histsql .= "VALUES ( ";
            $histsql .= "$client, ";
            $histsql .= "'$userid', ";
            $histsql .= "0.1, ";
            $email_header = "Sent e_mail re: " . $debtname . "<br />";
            $subject = $email_header . $subject;
            $subject = addslashes($subject);
            $histsql .= "'$subject', ";
            $body = addslashes($message);
            $histsql .= "'$body', ";
            $histsql .= "'$stamp' ) ";
            echo "<br />" . $histsql;
            if (mysql_query($histsql))  {
                write_txlog($histsql);
            } else {
                echo "<br />FAILED to ADD HISTORY (casenote) RECORD...";
                echo "<br />Notify your administrator immediately...";
                exit;
            }
            echo "<br />Looooooooks like the end of this loop ... ";
            exit; 
        }  // end IF mail sent
// SEND EMAIL ROUTINE HERE //
// SEND EMAIL ROUTINE HERE //
// SEND EMAIL ROUTINE HERE //

    }  // end IF $attachyorn == 'no' 
} // end of display_form        
}  // end if dbsuccess
exit;

?>

#

Thanks again ...

SP

Hello! I checked rapidly your code, I didn't tested but it seems fine, just few notes:

At line 78 you wrote:

$file = "Swift_Attachment::fromPath('" . $path . "')->setFilename=('" . $name . "', 'application/pdf'),";

fromPath() method supports two arguments (path and mime and the second is optional), while setFilename() supports only one argument, so the above needs to be changed to:

$file = "Swift_Attachment::fromPath('" . $path . "', 'application/pdf')->setFilename('" . $name . "')";

Note also that I've removed = character from setFilename and the comma at the end of the string. The main problem is that you're sending this as string but you have to feed the output, to the attach() method, not the command to execute, so remove the double quotes from the line:

$file = Swift_Attachment::fromPath('" . $path . "', 'application/pdf')->setFilename('" . $name . "');

This can also be rewritten as:

$file = Swift_Attachment::fromPath($path, 'application/pdf')->setFilename($name);

You can avoid array_push and use directly this solution:

$attachment[] = Swift_Attachment::fromPath($path, 'application/pdf')->setFilename($name);

Last note, the attach method doesn't seem to support arrays as arguments, so you should loop the above array as:

foreach($attachment as $attach)
{
    $message->attach($attach);
}

Hope it helps.

I got a little further into the php with the changes. Except, I'm not sure exactly (line #) where to put the

foreach($attachment as $attach)
{
$message->attach($attach);
}

Thanks...

Line 222. Full block in your code starts at line 200:

$message = Swift_Message::newInstance()
  ->setContentType("text/html")
    // Give the message a subject
  ->setSubject($subject)
    // Give it a body
  ->setBody($body)
    // Set the From address with an associative array
  ->setFrom($gmail_id)
    // Set the Sender address with an associative array
  ->setSender($gmail_id)
    // Set the To addresses with an associative array
  ->setTo($to)
    // Set the cc addresses with an associative array
  ->setcc($cc)
    // Set the Bcc addresses with an associative array
  ->setBcc($bcc);

foreach($attachment as $attach)
{
    $message->attach($attach); // end Message create  
}

If this doesn't help, please, post the errors codes, it will be easier for us to help you.

OK, made suggested changes and tried again.
Program displayed the following when processing lines 75 thru 92.

ID = 1
path = /usr/local/www/apache22/data/Uploads/BLG-BLGFF-5005-52684-25676.pdf
name = TES
ID = 5
path = /usr/local/www/apache22/data/Uploads/BLG-BLG-5005-34505-15820.pdf
name = test on 4 August-2
ID = 6
path = /usr/local/www/apache22/data/Uploads/BLG-BLG-5005-35107-15963.pdf
name = test on 9 August

HERE.... Line 90

Looks like line 228 throws the following errors, which I read to say
the file is NOT found where SwiftMailer wants it to be???

PHP Warning:
fopen(/usr/local/www/apache22/data/Uploads/BLG-BLGFF-5005-52684-25676.pdf):
failed to open stream: No such file or directory
in /usr/local/www/apache22/data/Swift-4.3.1/lib/classes/Swift/ByteStream/FileByteStream.php on line 138,
referer: http://10.10.10.112/mybkfiles/email_client_20.php?msg=13

PHP Fatal error:
Method Swift_Message::__toString() must not throw an exception in
/usr/local/www/apache22/data/mybkfiles/email_client_20.php on line 228,
referer: http://10.10.10.112/mybkfiles/email_client_20.php?msg=13

Thanks so much for the help ...

Code follows:

<?php
/*====================================
*   File:       email_client_20.php
*   By:         Steve Petruska
*   Date:       4/30/13
*
*   This script *
*=====================================
*/
$module = "email_client_20.php";
date_default_timezone_set("America/Los_Angeles");
$_SERVER['DOCUMENT_ROOT'] .= (substr($_SERVER['DOCUMENT_ROOT'],-1)=='/')?'':'/'; 
include $_SERVER['DOCUMENT_ROOT'] . 'mybkfiles/include/NEW_php-main.inc.php';
include $_SERVER['DOCUMENT_ROOT'] . 'mybkfiles/include/include_database.php';
// ##### Functions ##### //
// ##### Functions ##### //
$userid = $_SESSION['userid'];
$company = $_SESSION['company'];
$office = $_SESSION['office'];
###################   connect to database ##############################
$dbSuccess = false;
$dbConnected = mysql_connect($db['hostname'],$db['username'],$db['password']);

if ($dbConnected) {     
    $dbSelected = mysql_select_db($db['database'],$dbConnected);
    if ($dbSelected) {
        $dbSuccess = true;
    } else {
        echo "MySQL connection FAILED<br /><br />";
    }  // end dbSelected
} else {
    echo "DB connection FAILED<br /><br />";
    echo "<br />host = " . $db['hostname'] ;
    echo "<br />User " .  $db['username'];
    echo "<br />Password = " . $db['password'] ;
    echo "<br />Database = " . $db['database'];
}  // end dbConnected
//  END Secure Connection Script
//   Execute code ONLY if connections were successful 
include $_SERVER['DOCUMENT_ROOT'] . '/mybkfiles/include/include_gmail.php';
$templateURL = 'include/eMailTemplate_10.html';
require_once 'lib/swift_required.php';
$doc_path = $_SERVER['DOCUMENT_ROOT'] . 'Uploads/';
if ($dbSuccess)  {

        /// Check if SUBMIT is pressed
    $output_form = 'NO';
    $email_subject = "";
    $date_null = "0000-00-00 00:00:00";
    if ( isset($_GET['msg']) ) {
        $message = $_GET['msg'];
    } elseif ( isset($_POST['message']) ) {
        $message = $_POST['message'];
    } else {
        echo "<br />OOPS!!!!   Message number NOT found...";
        echo "<br />Notify your administrator immediately...";
        exit;
    } // end IF

        /// Check if SUBMIT is pressed
    $output_form = 'NO';
    $email_subject = "";
    $date_null = "0000-00-00 00:00:00";
    if ( isset($_POST['submit']) ) { 
        $attachments = array(); 

        if ( sizeof($_POST['selectfile']) ) {
            $output_form = 'NO';
            //print_r_html($_POST['selectfile']);
            $checkbox = $_POST['selectfile'];
            $path_name = $_POST['selectloc'];
            $file_name = $_POST['selectname'];
            print_r_html($checkbox);

            foreach ( $checkbox as $id ) {
                echo "<br />ID = " . $id ;
                $path = $path_name[$id];
                $path = $doc_path . $path;
    // test for vALID PATH
                //echo "<br />path = " . $path_name[$id];
                echo "<br />path = " . $path;
                $name = $file_name[$id];
                echo "<br />name = " . $file_name[$id];
                //$file = "Swift_Attachment::fromPath('" . $path . "')->setFilename=('" . $name . "', 'application/pdf'),";
                //$file = "Swift_Attachment::fromPath('" . $path . "', 'application/pdf')->setFilename('" . $name . "')";
                $file = Swift_Attachment::fromPath($path, 'application/pdf')->setFilename($name);
                $attachment[] = Swift_Attachment::fromPath($path, 'application/pdf')->setFilename($name);
                //array_push($attachments, $file);  
            } // end FOREACH
            //print_r_html($attachment);
            $output_form = 'NO';
            echo "<br />HERE.... Line 92";
            //exit;
        } else {
            echo '<p class="error">You did NOT SELECT any FILES to ATTACH to your e_mail';
            $output_form = 'YES';   
        } // end IF     

        //echo "<br />End of Validation ....";
    //exit;
    } else {
        $output_form = 'YES';
    }   // end of IF Submit was pressed
    if ($output_form == 'YES' ) {
        //echo "<br />Display Form here ...";
        //    Get message from maillog table
        $SQLselect = "SELECT ";
        $SQLselect .= "* ";     // <<  attributes
        $SQLselect .= "FROM ";
        $SQLselect .= "maillog ";           //  << table name
        $SQLselect .= "WHERE ";
        $SQLselect .= "email_id = '$message' ";         //  << attribute = $value

        $SQLselect_Query = mysql_query($SQLselect);     
        $row = mysql_fetch_object($SQLselect_Query);
        //print_r_html($row);
        $client = $row->email_client;
        $to = $row->email_to;           //      fieldName = an attribute name
        $from = $row->email_from;
        $cc = $row->email_cc;
        $bcc = $row->email_bcc;
        $subject = $row->email_subject;
        $body = $row->email_body;
        $attach = $row->email_attach;
        $to = unserialize($to);
        $cc = unserialize($cc);
        $bcc = unserialize($bcc);
        //print_r_html($to);
        //print_r_html($cc);
        //print_r_html($bcc);
        //exit;
        include $_SERVER['DOCUMENT_ROOT'] . '/mybkfiles/include/header.php';

        $email_org = "<p align='left'>";
        $email_org .= "<br />TO: ";
        foreach ($to as $value) {
            $email_org .= "<br />" . $value;
        }  // end FOREACH
        $email_org .= "<br />CC: ";
        foreach ($cc as $value) {
            $email_org .= "<br />" . $value;
        }  // end FOREACH
        $email_org .= "<br />BCC: ";
        foreach ($bcc as $value) {
            $email_org .= "<br />" . $value;
        }  // end FOREACH
        $email_org .= "<br />SUBJECT: " . $subject;
        $email_org .= "<br />Your E-Mail Message:<br />" . $body . "</p>";
        echo $email_org;

//  display form here
        $mail_form = "<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'>";
        $mail_form .= "<title>Send E-Mail</title></head>";

        $mail_form .=  "<form action='email_client_20.php' method='post' name='form1' enctype='multipart/form-data' type='text'>";
        $mail_form .=  "<table align='center' width=300px cellspacing=3 cellpadding=3 border=1>";
        $mail_form .=  "<tr><th colspan=2 align='center'> ATTACH SELECTED FILES<br />(Five (5) Files MAXIMUM)</th></tr>";
        //$mail_form .=  "<tr><td></td></tr>";

        $LIKE = " LIKE " . "'%-" . $client . "-%'"; 
        $filesql = "SELECT ";
        $filesql .= "* ";       // <<  attributes
        $filesql .= "FROM ";
        $filesql .= "documents, dochist ";          //  << table name
        $filesql .= "WHERE ";
        $filesql .= "doc_link $LIKE ";          //  << attribute = $value
        $filesql .= "AND ";
        $filesql .= "docrec = doc_id ";
        $filesql .= "ORDER BY doc_mod";
        $filesql_Query = mysql_query($filesql); 
        $count = 0;
        while ($filerow = mysql_fetch_array($filesql_Query, MYSQL_ASSOC)) {
            //print_r_html($filerow);
            $fileloc = $filerow['doc_link'];
            $filename = $filerow['doc_mod'];
            //echo "<br />loc = " . $fileloc;
            //echo "<br />name = " . $filename ;
            //$mail_form .= "<tr><td>" . $fileloc . "</td><td>" . $filename . "</td></tr>";
            //$mail_form .= "<td align='center'><input type='radio' name='send_debt' value='cc' /></td>";
            $mail_form .= "<tr><td align='center'><input type='checkbox' name='selectfile[]' value=" . $count . " /></td>"; 
            $mail_form .= "<td align='left'><input type='text' name='selectname[]' size=30 value='" . $filename . "' />";
            $mail_form .= "<input type='hidden' name='selectloc[]' size=60 value='" . $fileloc . "' /></td></tr>";
            $count++;
        }  // end WHILE

        $mail_form .=  "<tr><td colspan=2 align='center'><input type='submit' name='submit' style='font-weight: bold; background-color:#006400;color:#FFFFFF;' value='Send e-Mail' />";
        $mail_form .=  "<input type='hidden' value='$message' name='message'><input type='hidden' name='clno' value='$client'></td></tr></table></form>";
        $mail_form .=  "</body></html>";
        echo "<br />" . $mail_form;  
    } else {
// SEND EMAIL ROUTINE HERE //
// SEND EMAIL ROUTINE HERE //
// SEND EMAIL ROUTINE HERE //
    $body  = $email_body;
//#   BEGIN - Create the Transport ########################################################################
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
  ->setUsername($gmail_id)
  ->setPassword($gmail_pswd)
;   // end $transport
// Create the Mailer using your created Transport

$mailer = Swift_Mailer::newInstance($transport);

{       //  Start of CREATE Message
// Create the message
$message = Swift_Message::newInstance()
    ->setContentType("text/html")
    // Give the message a subject
    ->setSubject($subject)
    // Give it a body
    ->setBody($body)
    // Set the From address with an associative array
    ->setFrom($gmail_id)
    // Set the Sender address with an associative array
    ->setSender($gmail_id)
    // Set the To addresses with an associative array
    ->setTo($to)
    // Set the cc addresses with an associative array
    ->setcc($cc)
    // Set the Bcc addresses with an associative array
    ->setBcc($bcc);
    foreach($attachment as $attach)
    {
    $message->attach($attach); // end Message create
    }
;   // end of $message instance
}   // end of CREATE Message

echo "<br />Message =<br />" . $message;
echo "<br />HERE 2 .... Line 228";
//#   END - Create the Transport ########################################################################

#######################################################################
//  Process e-mail here // #########################################

$mailsql = "INSERT INTO maillog ( ";
$mailsql .= "email_firm, ";
$mailsql .= "email_client, ";
$mailsql .= "email_user, ";
$mailsql .= "email_from, ";
$mailsql .= "email_to, ";
$mailsql .= "email_cc, ";
$mailsql .= "email_bcc, ";
$mailsql .= "email_subject, ";
$mailsql .= "email_body, ";
$mailsql .= "email_attach, ";
$mailsql .= "email_sent ";
$mailsql .= ") ";
$mailsql .= "VALUES ( ";
$mailsql .= "'$company', ";
$mailsql .= "'$client', ";
$mailsql .= "'$userid', ";
$mailsql .= "'$email_from', ";
    $send_email_to = serialize($to);
$mailsql .= "'$send_email_to', ";
    $send_email_cc = serialize($cc);
$mailsql .= "'$send_email_cc', ";
    $send_email_cc = serialize($bcc);
$mailsql .= "'$send_email_bcc', ";

$mailsql .= "'$subject', ";
$mailsql .= "'$body', ";
$mailsql .= "'$attachyorn', ";
$mailsql .= "'$date_null' ";
$mailsql .= " )";
echo "<br />SQL = " . $mailsql;
if (mysql_query($mailsql))  {
    write_txlog($mailsql);
    $messno = mysql_insert_id();
    echo "<br />ADDed your e-mail to the database - seqno = $messno";
} else {
    echo "<br />FAILED to ADD your e-mail to the database";
    echo "<br />Notify your administrator immediately...";
    exit;
}
echo "<br />Message Number = " . $messno;

#######################################################################
echo "<br />attachyorn = " . $attachyorn ;
////exit;
    if ( $attachyorn == 'no' ) {
        if ( !$mailer->send($message, $failures) ) {
            echo "<br />Notify your administrator immediately...";
            echo "<br />Sending Message FAILED....See below for more info...";
            print_r_html($failures);
            exit;
        } else {
            //  Update email record with date/time stamp 
            $stamp = date("Y-m-d H:i:s", time()) ;
            $mailupdate = "UPDATE maillog ";
            $mailupdate .= "SET email_sent = '$stamp' ";
            $mailupdate .= "WHERE email_id = '$messno' ";
            $mailupdate .= "LIMIT 1";
            echo "<br />SQL = " . $mailupdate;
            if (mysql_query($mailupdate))  {
                write_txlog($mailupdate);
            } else {
                echo "<br />FAILED to UPDATE your e-mail as SENT...";
                echo "<br />Notify your administrator immediately...";
                exit;
            }
            //  Add history record with link to e-mail $messno, stating NO ATTACHMENTS were sent
            //echo "<br />Message was sent....";

            //$casenote = "E-mail sent to client Subject: " . $subject . "<br />";
            //$casenote .= "<a href='email_hist_link.php?msg=$messno'>View Email in NEW TAB</a>";
            $histsql = "INSERT INTO hist ( ";
            $histsql .= "hclient, ";
            $histsql .= "hemp, ";
            $histsql .= "htime, ";
            $histsql .= "hsubject, ";
            $histsql .= "hnote, ";
            $histsql .= "hstamp ) ";
            $histsql .= "VALUES ( ";
            $histsql .= "$client, ";
            $histsql .= "'$userid', ";
            $histsql .= "0.1, ";
            $email_header = "Sent e_mail re: " . $debtname . "<br />";
            $subject = $email_header . $subject;
            $subject = addslashes($subject);
            $histsql .= "'$subject', ";
            $body = addslashes($message);
            $histsql .= "'$body', ";
            $histsql .= "'$stamp' ) ";
            echo "<br />" . $histsql;
            if (mysql_query($histsql))  {
                write_txlog($histsql);
            } else {
                echo "<br />FAILED to ADD HISTORY (casenote) RECORD...";
                echo "<br />Notify your administrator immediately...";
                exit;
            }
            echo "<br />Looooooooks like the end of this loop ... ";
            exit; 
        }  // end IF mail sent
// SEND EMAIL ROUTINE HERE //
// SEND EMAIL ROUTINE HERE //
// SEND EMAIL ROUTINE HERE //

    }  // end IF $attachyorn == 'no' 
} // end of display_form        
}  // end if dbsuccess
exit;

?>

I see that the values are set by your form:

$path_name = $_POST['selectloc'];
$file_name = $_POST['selectname'];

Are you sure the path of the file is correct? Consider that in linux paths are case sensitive, so Uploads and uploads are different for the system. You can verify the paths with file_exists().

Also remove ; from line 226.

Congratulations! You're no longer a DaniWeb newbie.<br /> <br />
Your DaniWeb account has just been upgraded from newbie status and now you have the ability to take advantage of everything the community has to offer.<br /> <br />
You can now enjoy an advertisement-free DaniWeb by ticking the checkbox to Disable Ads in your profile. You will no longer have to fill out the human verification check when you post. You can also now send unlimited private messages, contribute new code snippets, and tag articles with never-before-used tags.

Cereal:

Thanks so much ... Sometimes we're so close to the problem it takes a shovel to get our attention... I'm sure glad u used a big enuff shovel!!!

Working fine until the actual sending of the email... looks like something's missing, so I'll dig for a while and see what's up. Thanks so much ...

You're welcome! In case of problems, post the error codes, we will try to help, bye!

Got it to work... attachments flowing like honey!!!! Spent a week golfing at 10,000 ft in Colorado, thin air ... TRhanks for all the help...

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.