/    Sign up×
Community /Pin to ProfileBookmark

Send link to a friend form. Multiple emails.

I have a form built in flash with a few input fields that needs to be able to send emails to multiple email address’. Right now the form is working but for only ‘one’ email address.

Can someone look at my code and explain a way that the form can send the email to multiple email address’, by separating the email address’ by commas in the input field?

Here is my code:

[QUOTE]

<?php

# Send to address

$sendTo = stripslashes($_POST[“friendsEmail_txt”]);

# Subject line

$subject = “TOONS: Your Friend Has Sent You a Movie!”;

# Send from address

$sendFrom = “FROM: [email][email protected][/email]“;

# Body

$body = “Check out this short animated movie, [Episode Title, hyperlinked], at toons.com.

[Episode thumbnail image, also hyperlinked]

Your friend” . stripslashes($_POST[” yourName_txt “]) . ” writes:

” . stripslashes($_POST[“friendsName_txt”]) . ” n n” . stripslashes($_POST[“yourName_txt”]) . “

If you are having problems opening the link, copy and paste the URL into your browser window:

[url]http://movie…com[/url]

Brought to you by the good folks at [Organization Name], CompanyURLhere.com.

For any questions, please contact us at ‘[email protected]‘.

“;

# Send mail

mail($sendTo, $subject, $body, $sendFrom);
?>

[/QUOTE]

Thanks!

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiNov 20.2008 — The easiest way would be to get an array from your comma-separated list of emails:

[code=php]$emails = explode(',', $_POST["friendsEmail_txt"]);[/code]

You can then loop through this array sending your email each time:

[code=php]foreach ($emails as $email) {
// send the mail here
}[/code]
Copy linkTweet thisAlerts:
@SyCoNov 20.2008 — You could also use the bcc header and only call mail() one time.
Copy linkTweet thisAlerts:
@MindzaiNov 20.2008 — You could also use the bcc header and only call mail() one time.[/QUOTE]

Good point ?
Copy linkTweet thisAlerts:
@crj900authorNov 20.2008 — Thanks guys. Could one of you implement that code into what I have above? I can't seem to get it to work...

Thanks,
Copy linkTweet thisAlerts:
@crj900authorNov 20.2008 — Also anyone who sets this up for me, and has a built in email verification ( that needs @ .com .net .edu etc) I will paypal over $20. The email box is "friendsEmail_txt"

I'll post the Actionscript also:

Here is the AS in my flash:

//Clear the form

function init(){

// Set Tab ordering

yourName_txt.tabIndex=1;

friendsName_txt.tabIndex=3;

friendsEmail_txt.tabIndex=2;

// Clear Text

yourName_txt.text="";

friendsName_txt.text="";

friendsEmail_txt.text="";

// Trigger the errors

error1=1;

error2=1;

error3=1;

formSuccess=1;
}

function checkForm(){

// Check the value of your name

if(yourName_txt.text==""||yourName_txt.text==""){

error1=0;

yourName_txt.text="";

}else{

error1=0;

}

// Check the value of the friend's name

if(friendsName_txt.text==""||friendsName_txt.text==""){

error2=0;

friendsName_txt.text="";

}else{

error2=0;

}

// Make sure it's email address format

if(friendsEmail_txt.text==""||friendsEmail_txt.text=="email address required"){

error4=1;

friendsEmail_txt.text="email address required";

}else{

error3=0;

}

// If everything checks out...

if(error1==0&&error2==0&&error3==0){

formSuccess=0;

}

}

// Success function

function giveThanks(){

// Clear text

yourName_txt.text="";

friendsName_txt.text="";

friendsEmail_txt.text="";

formSuccess=1;

gotoAndStop(2);

}

// Submit button

function submit(){

// Run error checking

checkForm();

if(formSuccess==0){

// Set up variables to go to php script

var sendEmailVars:LoadVars = new LoadVars();

sendEmailVars.yourName_txt = yourName_txt.text;
sendEmailVars.friendsName_txt = friendsName_txt.text;
sendEmailVars.friendsEmail_txt = friendsEmail_txt.text;

sendEmailVars.sendAndLoad("mail.php", sendEmailVars, "POST");
giveThanks();
}

}

// Clear form, initialize variables

init();

submit_btn.onRelease=function(){

submit();

}
[/QUOTE]
Copy linkTweet thisAlerts:
@crj900authorNov 21.2008 — Anyone? I'm in somewhat of a rush.
Copy linkTweet thisAlerts:
@MindzaiNov 21.2008 — Well, it's hard to fix without knowing the problem you are having, but the following should work.

[code=php]// subject line
$subject = 'TOONS: Your Friend Has Sent You a Movie!';

// send from address
$from = '[email protected]';

// body
//
// NB: "n" will not give you a new line in a html email which this seems to be. you
// need to use "<br />". "n" will just place a new line in the source code
$body = 'Check out this short animated movie, [Episode Title, hyperlinked], at toons.com.
[Episode thumbnail image, also hyperlinked]
Your friend' . stripslashes($_POST['yourName_txt']) . ' writes:' .
stripslashes($_POST['friendsName_txt']) . "nn" . stripslashes($_POST['yourName_txt']) . '
If you are having problems opening the link, copy and paste the URL into your browser window:
http://movie...com
Brought to you by the good folks at [Organization Name], CompanyURLhere.com.
For any questions, please contact us at '[email protected]'.';

// assuming $_POST['friendsEmail_txt'] contains a comma-separated list of emails
// like so '[email protected], [email protected], [email protected]', the
// emails can be extracted into an array as follows:
$emails = explode(',', stripslashes($_POST['friendsEmail_txt']));

// send the mails
foreach ($emails as $email) {
mail(trim($email), $subject, $body, $from);
}[/code]


This is assuming you want to send each person an individual email. You could also use SyCo's suggestion of using BCC instead if you wanted to.

As far as the actionscript goes I don't use it so I can't help you there.
×

Success!

Help @crj900 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.28,
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,
)...