attach multiple files ALREADY on server

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
Forum Newbie
Posts: 1
Joined: Thu Jun 27, 2013 1:24 pm

attach multiple files ALREADY on server

Post by trainview »

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:
[text] 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:
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

Code: Select all

if ( isset($_POST['submit']) ) { 
		$attachments = array();	

		if ( sizeof($_POST['selectfile']) ) {
			$output_form = 'NO';
			$checkbox = $_POST['selectfile'];
			$path_name = $_POST['selectloc'];
			$file_name = $_POST['selectname'];
			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
			$output_form = 'NO';
			echo "<br />HERE....";
		} 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 ....";
	} else {
		$output_form = 'YES';
	}   // end of IF Submit was pressed
And trying to populate the SwiftMailer Instance with the following:

Code: Select all

include $_SERVER['DOCUMENT_ROOT'] . '/mybkfiles/include/include_gmail.php';
$templateURL = 'include/eMailTemplate_10.html';
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('', 465, 'ssl')
;   // 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()
	// Give the message a subject
	// Give it a body
	// Set the From address with an associative array
	// Set the Sender address with an associative array
	// Set the To addresses with an associative array
	// Set the cc addresses with an associative array
	// Set the Bcc addresses with an associative array

// 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...
Post Reply