
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: http://10.10.10.112/mybkfiles/email_client_20.php?msg=5
[/text]
and of course, I have no idea what it's trying to tell me, hence the




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';
//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
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('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???




Thanks in advance...