/    Sign up×
Community /Pin to ProfileBookmark

How to set email addresses in a variable?

Would this be the best way to set these email addresses in a variable? Or would an array be better?

[code=php]$others = “[email protected], [email protected], [email protected]”;

$headers = “From: [email protected]”;
$headers .= “Bcc: $othersrn”;
$headers .= “Content-Type: text/plain; charset=iso-8859-1rn”;

mail($email, $subject, $message, $headers);[/code]

Thanks

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordMar 04.2009 — sometimes the spaces in the $others variable might not work

[code=php]
// You have
$others = "[email protected], [email protected], [email protected]";

// Try
$others = "[email protected],[email protected],[email protected]";
[/code]
Copy linkTweet thisAlerts:
@NogDogMar 04.2009 — You could use an array, but whether or not it is "better" depends on your criteria for "better". For instance, you could use arrays and implode() something like this:
[code=php]
$others = array(
'[email protected]',
'[email protected]',
'[email protected]'
);
$headers = array(
'From: [email protected]',
'Bcc: ' . implode(', ', $others),
'Content-Type: text/plain; charset=iso-8859-1',
'X-Mailer: PHP/' . phpversion()
);
mail($to, $subject, $message, implode("rn", $headers));
[/code]
Copy linkTweet thisAlerts:
@Alan_PauthorMar 04.2009 — Thanks both!
×

Success!

Help @Alan_P 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.22,
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,
)...