PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Oct 22, 2017 7:23 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Thu Jun 27, 2013 1:57 pm 
Offline
Forum Newbie

Joined: Thu Jun 27, 2013 1:24 pm
Posts: 1
:banghead:
I'm trying to attach files, already loaded to the server, to swiftmailer emails. User selects files from a FORM list, then, I'm trying to attach the 'clicked' files to an e-mail. When the e-mail tries to send, I get:
Syntax: [ Download ] [ Hide ]
 PHP Catchable fatal error:  Argument 1 passed to Swift_Mime_SimpleMessage::attach() must implement interface Swift_Mime_MimeEntity, array given, called in /usr/local/www/apache22/data/mybkfiles/email_client_20.php on line 221 and defined in /usr/local/www/apache22/data/Swift-4.3.1/lib/classes/Swift/Mime/SimpleMessage.php on line 529, referer: http://10.10.10.112/mybkfiles/email_client_20.php?msg=5
 

and of course, I have no idea what it's trying to tell me, hence the :banghead: :banghead: :banghead: :banghead:
Basically I'm attempting to populate the attachment list by the following after <SUBMIT> is pressed
Syntax: [ Download ] [ Hide ]
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


And trying to populate the SwiftMailer Instance with the following:
Syntax: [ Download ] [ Hide ]
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;
 

====================================================
Can get a hand here??? :banghead: :banghead: :banghead: :banghead:

Thanks in advance...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group