View Full Version : How can I add multiple recipients to my contact form?
chaz33
September 24th, 2009, 08:35
I have a contact form on my website. I want the message to be deliver to another email address. How can I do that?
Tracker
September 24th, 2009, 11:55
As in you want it to deliver to more than one person? Easy way would be go create an email account such as contactform@site.com and then have all messages sent to that and use a forwarder to send them to all the people you desire. Depending on how your contact form is setup you can add more than one person however I dont know your code base so I cant answer the question on how to do it with out creating an email forwarder.
Hope this helps :)
iBrightDev
September 24th, 2009, 12:13
just use a textarea for the input, use commas to separate the email addresses, then use php to put the contents of the input in an array. explode the array where the commas are, and then do a foreach loop to go through all the addresses found, and separate emails will be sent to each person.
below is an example of my code that i am just posting here. this is not going to just work for you with a copy paste since there are some objects being called, but, you should be able to get the idea of what to do.
//incase someone entered down a line, lets remove breaks
$destroy = array(', ', '\r', '\n', '\r\n', '<br/>', '<br>');
//replace the breaks with nothing
$fix = array(',', '', '', '', '', '');
//do a string replace for any breaks found and replace them
$to = str_replace($destroy, $fix, $to);
//take our new string and explode it where commas are found
$to = explode(",", $to);
//reset the string for handling
reset($to);
//loop through all found emails individually
foreach ($to as $eTo) {
$emailTo = $eTo;
$emailFrom = $details['email'];
$emailSubject = $subject;
$emailBody = "{$message}<br>".
"<br>".
"------------------------------------------------------------------------<br>".
"Message initiated by " . $_SERVER['REMOTE_ADDR'] . " on " . date("y-m-d") . " " . date("H:i:s") . "<br>".
" from source URL " . ADMIN_CURRENT_URL . "<br><br>".
"";
//$emailBody = strip_tags($emailBody);
$emailBody = stripslashes($emailBody);
$emailHeader = "From: $emailFrom\nReply-To: $emailFrom\nReturn-Path: $emailFrom\n".
"MIME-Version: 1.0\n".
"Content-Type: text/html; charset=\"iso-8859-1\"\n".
//"Content-type: text/plain; charset=\"ISO-8859-1\"\n".
"Content-transfer-encoding: 8bit\n";
# Send message, redirect on success
if (mail($emailTo, $emailSubject, $emailBody, $emailHeader))
$s .= 'Your message has been sent to ' . $emailTo . '.<br/>'.$bL;
else
$s .= '<span style="color: #ac0000">There was a problem sending your message to ' . $emailTo . '.</span><br/>'.$bL;
}
//echo the success or error message from the above if statement.
echo $msgs -> successMsg($s);
here is my form, just in case you need to see it...
<form action="<?=ADMIN_CURRENT_URL?>" method="post">
<div class="float-left" style="width: 120px;"><strong>Recipient(s):</strong></div>
<textarea name="to" id="to" class="inpt-txt-area" style="width: 420px;" rows="2"><?=$_POST['to']?></textarea>
<div class="clear-left"></div>
<div class="spacer10"></div>
<div class="float-left" style="width: 120px;"><strong>Subject:</strong></div>
<input class="inpt-bx float-left" style="width: 420px;" type="text" name="subject" value="<?=$_POST['subject']?>" />
<div class="clear-left"></div>
<div class="spacer10"></div>
<div class="float-left" style="width: 120px;"><strong>Message:</strong></div>
<textarea name="message" id="message" class="inpt-txt-area" style="width: 420px;" rows="8"><?=stripslashes($_POST['message'])?></textarea>
<div class="clear-left"></div>
<div class="spacer10"></div>
<div class="float-left" style="width: 120px; height: 1px"></div>
<input type="submit" value="Send E-Mail Now" name="Submit" class="form-btn float-left" />
<div class="clear-left"></div>
<input type="hidden" name="submitted" value="TRUE" />
</form>
chaz33
September 25th, 2009, 04:56
just use a textarea for the input, use commas to separate the email addresses, then use php to put the contents of the input in an array. explode the array where the commas are, and then do a foreach loop to go through all the addresses found, and separate emails will be sent to each person.
below is an example of my code that i am just posting here. this is not going to just work for you with a copy paste since there are some objects being called, but, you should be able to get the idea of what to do.
//incase someone entered down a line, lets remove breaks
$destroy = array(', ', '\r', '\n', '\r\n', '<br/>', '<br>');
//replace the breaks with nothing
$fix = array(',', '', '', '', '', '');
//do a string replace for any breaks found and replace them
$to = str_replace($destroy, $fix, $to);
//take our new string and explode it where commas are found
$to = explode(",", $to);
//reset the string for handling
reset($to);
//loop through all found emails individually
foreach ($to as $eTo) {
$emailTo = $eTo;
$emailFrom = $details['email'];
$emailSubject = $subject;
$emailBody = "{$message}<br>".
"<br>".
"------------------------------------------------------------------------<br>".
"Message initiated by " . $_SERVER['REMOTE_ADDR'] . " on " . date("y-m-d") . " " . date("H:i:s") . "<br>".
" from source URL " . ADMIN_CURRENT_URL . "<br><br>".
"";
//$emailBody = strip_tags($emailBody);
$emailBody = stripslashes($emailBody);
$emailHeader = "From: $emailFrom\nReply-To: $emailFrom\nReturn-Path: $emailFrom\n".
"MIME-Version: 1.0\n".
"Content-Type: text/html; charset=\"iso-8859-1\"\n".
//"Content-type: text/plain; charset=\"ISO-8859-1\"\n".
"Content-transfer-encoding: 8bit\n";
# Send message, redirect on success
if (mail($emailTo, $emailSubject, $emailBody, $emailHeader))
$s .= 'Your message has been sent to ' . $emailTo . '.<br/>'.$bL;
else
$s .= '<span style="color: #ac0000">There was a problem sending your message to ' . $emailTo . '.</span><br/>'.$bL;
}
//echo the success or error message from the above if statement.
echo $msgs -> successMsg($s);
here is my form, just in case you need to see it...
<form action="<?=ADMIN_CURRENT_URL?>" method="post">
<div class="float-left" style="width: 120px;"><strong>Recipient(s):</strong></div>
<textarea name="to" id="to" class="inpt-txt-area" style="width: 420px;" rows="2"><?=$_POST['to']?></textarea>
<div class="clear-left"></div>
<div class="spacer10"></div>
<div class="float-left" style="width: 120px;"><strong>Subject:</strong></div>
<input class="inpt-bx float-left" style="width: 420px;" type="text" name="subject" value="<?=$_POST['subject']?>" />
<div class="clear-left"></div>
<div class="spacer10"></div>
<div class="float-left" style="width: 120px;"><strong>Message:</strong></div>
<textarea name="message" id="message" class="inpt-txt-area" style="width: 420px;" rows="8"><?=stripslashes($_POST['message'])?></textarea>
<div class="clear-left"></div>
<div class="spacer10"></div>
<div class="float-left" style="width: 120px; height: 1px"></div>
<input type="submit" value="Send E-Mail Now" name="Submit" class="form-btn float-left" />
<div class="clear-left"></div>
<input type="hidden" name="submitted" value="TRUE" />
</form>
Thanks for your reply mate, but my free hosting does not allow PHP code :(.
I think my only option is some 3rd party form processors that will do all the "dirty work". So far I found that http://www.123contactform.com has a multiple recipients feature, but if you have a better solution please let me know.
KilobyteSite.com
September 26th, 2009, 08:58
What are you currently using for the contact form?
iBrightDev
September 29th, 2009, 00:08
Thanks for your reply mate, but my free hosting does not allow PHP code :(.
I think my only option is some 3rd party form processors that will do all the "dirty work". So far I found that http://www.123contactform.com has a multiple recipients feature, but if you have a better solution please let me know.
sorry to hear that. maybe look into getting paid hosting for a reasonable cost. it would be worth it. :)
themoose
September 30th, 2009, 21:45
Or some decent free hosting.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.