Created
September 18, 2012 18:04
-
-
Save faridjame/3744706 to your computer and use it in GitHub Desktop.
PHP: send multi attachment emails with swiftmailer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('swift/lib/swift_required.php'); | |
$email = $_POST['email']; | |
$subject = "my subject"; | |
$user_message = "<b>message body</b>"; | |
$mailer = new Swift_Mailer(new Swift_MailTransport()); | |
$message = Swift_Message::newInstance(); | |
$message->setSubject($subject); | |
$message->setFrom(array($email)); | |
$message->setTo(array('[email protected]')); | |
$message->setCc(array('[email protected]')); | |
$message->setBody($user_message, 'text/html'); | |
for ($i=0; $i < count($_FILES['attachment']); $i++) { | |
$target_path = "uploads/" . basename($_FILES['attachment']['name'][$i]); | |
if( move_uploaded_file($_FILES['attachment']['tmp_name'][$i], $target_path) ) { | |
$message->attach(Swift_Attachment::fromPath($target_path)); | |
//if we don't want to keep the image | |
unlink($target_path); | |
} | |
} | |
$mailer->send($message); | |
header("location:thank_you.html"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way to select one image/file at a time in Swiftmailer? i.e. Open the File Upload/Windows Explorer and double click the file then re-open the File Upload/Windows Explorer and select another file, thus appending to the array of attachments?