Page 1 of 1

swiftmailer and attachments from recordset?

Posted: Mon Sep 22, 2008 1:29 pm
by student101
Is the correct Method to add attachments?
I grabbed code as I searched in this forum - it aint sending the file.

Code: Select all

require_once "lib/Swift.php";
require_once "lib/Swift/Connection/NativeMail.php"; //There are various connections to use
$swift =& new Swift(new Swift_Connection_NativeMail());
$message =& new Swift_Message("Event added");
$email_message2 = nl2br($_POST['memdescription']);
$email_message = ""; // Message that the email has in it 
//$email_message .= nl2br($_POST['memdescription'])."\n";
$email_message .= "-----------------------------" . "\n";
$email_message .= "Event added:" . "\n";
$email_message .= "-----------------------------" . "\n";
$email_message .= "\n";
$email_message .= "Heading: " . $_POST['txtHeading'] . "\n";
$email_message .= "Description: " . email_message2 . "\n";
$email_message .= "User: " . $_POST['userid'] . "\n";
$email_message .= "Email address: " . $_POST['userid'] . "\n";
 
$message->attach(new Swift_Message_Part($email_message));
 
$filecount = 0;
foreach ($_FILES["txtdownload"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
 
$tmp_name = $_FILES["txtdownload"]["tmp_name"][$key];
$oname = $_FILES["txtdownload"]["name"][$key];
$name = "uploads/downloads/$oname";
move_uploaded_file($tmp_name,$name);
 
$result = $message->attach(new Swift_Message_Attachment(new Swift_File("$name"),"$oname"));
if ($result == false) { echo "\n Adding $name failed !\n"; }
}
}
//Now check if Swift actually sends it
if ($swift->send($message, "email@example.com", "email@example.com")){ 
echo "Email Sent";
}else{
echo "Message failed to send";
}
Cheers

Re: Correct method to add attachments?

Posted: Mon Sep 22, 2008 2:15 pm
by student101
I think this is the solution for me;

http://www.swiftmailer.org/wikidocs/v3/ ... /form2mail

Cheers

swiftmailer and attachments from recordset?

Posted: Tue Sep 23, 2008 3:10 am
by student101
It only sends attachments that are fixed like this;

Code: Select all

 
"uploads/downloads/filename.pdf"
 
Not like this;

Code: Select all

 
$_FILES[$row_rsev['txtdownload']
 
Any ideas on getting it from the recordset?

Cheers

Re: swiftmailer and attachments from recordset?

Posted: Wed Sep 24, 2008 4:29 pm
by student101
Bumping this to hopefully get at least a response to a tutorial or any sort of help possible?

How to attach using a recordset and the folder it's saved to?