swiftmailer and attachments from recordset?
Posted: Mon Sep 22, 2008 1:29 pm
Is the correct Method to add attachments?
I grabbed code as I searched in this forum - it aint sending the file.
Cheers
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";
}