Click to See Complete Forum and Search --> : Emailing (with an attachment) to an array of email ids


ashishrathore
03-25-2006, 05:09 AM
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 www.phpmailer.sourceforge.net for email broadcast


$mail = new PHPMailer();

foreach ($email as $id)
{

$mail->From = "ashish@reachindians.com";
$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>";
}

}

?>
======================================================

Speedydomain
03-25-2006, 05:34 PM
To pass array to php, I believe you'd need to use something like emailids[] for field name in the html form.