Moving Attachments To Folder And Attaching Them With Email

Moving attachments to folder and attaching them with email
Posted Today, 12:24 PM
I have a simple page, which is sending an Email message and multiple attachments, through phpmailer.
I have to attach the multiple attachments to the Email message to send, and also upload these files o server at same time, For which i m using the following loop:

[php] $MyUploads = array();

 foreach(array_keys($_FILES['attach']['name']) as $key)

{ $Location=“uploads/”;

$name=$_FILES[‘attach’][‘name’][$key];

$filePath = $Location . $name;

$source = $_FILES[‘attach’][‘tmp_name’][$key]; // location of PHP’s temporary file for this.

$tmp=$_FILES[‘attach’][‘tmp_name’][$key];

if($mail->AddAttachment($source, $name))

{if(move_uploaded_file($tmp, $filePath)){

$MyUploads[] = $filePath;}

else

{$MyUploads[]=’’;

echo “not uploaded”;}

}
}[/php]

The problem is, when i use the function move_uploaded_file(), the files are uploaded to the server folder, but are not sent with the attachments. As i comment out this function the attachments are sended.

Can;t find out, why these two dnt work together. Please any body help

Your mail has nothing to do with the uploading of the file. This is two separate functions.
This code:

if($mail->AddAttachment($source, $name)) {if(move_uploaded_file($tmp, $filePath)){ $MyUploads[] = $filePath;} else {$MyUploads[]=''; echo "not uploaded";} } }
Should be more like this: [php]

if($mail->AddAttachment($source, $name)) {
echo “Your email was sent!”;
} else {
echo “You email was not sent!”;
}

if(move_uploaded_file($tmp, $filePath)) {
$MyUploads[] = $filePath;
} else {
$MyUploads[]=’’;
echo “File not uploaded”;}
}

[/php]

Not sure if that is what you were asking. Hope it helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service