Multiple attachments code

I have made an Email Form with multiple attachments ,. The code i am using is as follows: The error is when i have written the Loop for multiple attachments, and set all the code on the Submit button event, Nothing happens… Before, it. Mail is sent, with the attachments except the loop attachments

[php]<?php
(isset($_POST[‘Submit1’]))
{
include “class.phpmailer.php”;
$From = "[email protected]";
$FromName = “From Name”;
$To = "[email protected]";
$ToName = “To Name”;
$Subject = “Hello there, you will receive some files”;
$Body = “This is a test email which includes attachment”;

$mail = new PHPMailer();

$mail->From = $From;
$mail->FromName = $FromName;

$mail->AddAddress($To , $ToName);

$mail->WordWrap = 50; // set word wrap
$mail->Priority = 1;
$mail->IsHTML(true);
$mail->Subject = $Subject;
$mail->Body = $Body;

foreach($_FILES as $key => $file){
$target_path = “uploads/”;
$target_path = $target_path .basename($file[‘name’]);

if(move_uploaded_file($file[‘tmp_name’], $target_path)) {
echo “the file “.basename($file[‘name’]).” has been uploaded”;
}else {
echo “there was an error”;
}
$mail->AddAttachment($target_path);
}
$mail->AddAttachment(“imgj.jpg”);
$mail->AddAttachment(“Mailbox.png”); // attachment

if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo ‘Message has been sent.’;

}
}
?>[/php]
Wud any one tell me, why is this php code doing nthng

you answered the question yourself. the mail is being sent out before the attachments. you need to move the send part after the attachments. I also don’t see any paths to tell it where those attachments are located.

I would look up the documentation on the class that you’re using. it might have examples.

Your code is messed up in that FILES section…

Try this, take out everything between
“$mail->Body = $Body;”
and
“$mail->AddAttachment(“imgj.jpg”);”
(All of the files section)

Then, see if it posts an email okay. If it does, then the bad part is the files mess.
By the way, where does it get the files part? It doesn’t even have a folder to get files from? Is this string passed from code we do not see?

Anyway, test the email with that part so we can see if it is the email part or the files parts…
Let us know…

Sponsor our Newsletter | Privacy Policy | Terms of Service