/    Sign up×
Community /Pin to ProfileBookmark

Emailing (with an attachment) to an array of email ids

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[/url] for email broadcast

$mail = new PHPMailer();

foreach ($email as $id)
{

$mail->From = “[email protected]“;
$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>”;
}

}

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

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@SpeedydomainMar 25.2006 — To pass array to php, I believe you'd need to use something like emailids[] for field name in the html form.
×

Success!

Help @ashishrathore spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...