hi,
i had made an email broadcast page
in that i am abel to deliver an email along with an attachment to a single email- id
but when i pass an array of email-ids the only email is send to the respective email-ids and not the attachment ( the main problem that i am getting is the file that has to be attached is not getting uploaded on the server in case of multiple email-ids ; while the file is getting uploaded , in case of a single email-id)
here is my code
=====================CODE================================
<?
$email = $_SESSION[’emailids’]; /// this is an array of email-ids
$subject= $_SESSION[‘subject’]; //// this is the subject
$message = $_SESSION[‘message’]; //// message body
$n = count($email);
$count = 0;
$fname = $_FILES[‘userfile’][‘name’]; // this is the file to be attached
if($fname==””)
{
}
else
{
$uploaddir = “./userfile/”; /// userfile is the directory on the web server where the file is going to be uploaded
$tmpname = explode(” “,$fname);
$tmpcount = count($tmpname);
$finname = $tmpname[0];
for($t=1;$t<$tmpcount;$t++)
{
$finname = $finname . $tmpname[$t];
}
$fname = $finname;
$pic= $fname;
echo $fname;
$myp=$pic;
if(move_uploaded_file($_FILES[‘userfile’][‘tmp_name’], $uploaddir . $_FILES[‘userfile’][‘name’]))
{
rename($uploaddir . $_FILES[‘userfile’][‘name’],$uploaddir . $myp);
}
else
{
// do nothing
}
}
require(“class.phpmailer.php”); /// i am using this class from [url]www.phpmailer.sourceforge.net
$mail = new PHPMailer();
foreach ($email as $id)
{
$mail->From = “
$mail->FromName = “Ashish Rathore”;
$mail->AddAddress($id) ; //// the “FOREACH” value of email-id
$mail->AddAttachment(“userfile/$pic”); /// userfile is the directory on the server where the attached file is going to get uploaded
$mail->IsHTML(true); // send as HTML
$mail->Subject = $subject ; //////// “Here is the subject”;
$mail->Body = $message ; //////// “This is the <b>HTML body</b>”;
if(!$mail->Send())
{
echo “Message was not sent <p>”;
echo “Mailer Error: ” . $mail->ErrorInfo;
exit;
}
else
{
//echo $email[$i].”<br>”;
}
}