?
Solved

PHP form submission to multiple emails

Posted on 2007-11-14
3
Medium Priority
?
1,040 Views
Last Modified: 2008-02-01
I am trying to let customers select who they send the email to on a contact form I am sure I have just one little thing wrong could someone please check it out thank you

Here is the html code for my form:
<form id="Contact" action="contact.php" method="post" name="Contact">
                                    <table width="65%" border="0" cellspacing="2" cellpadding="2" bgcolor="white">
                                          <tr height="10">
                                                <td width="198" height="10"></td>
                                                <td width="100" height="10"></td>
                                                <td width="369" height="10"></td>
                                          </tr>
                                          <tr height="30">
                                                <td rowspan="5" valign="top" width="198" height="362"><font face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">Address:<br />
                                                            Imagination Graphics, Inc.<br />
                                                            1503 N. 4th<br />
                                                            Coeur d' Alene,<br />
                                                            Idaho 83814</font>
                                                      <div align="left">
                                                            <p><font face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">P.O. Box 2637<br />
                                                                        Coeur d' Alene,<br />
                                                                        Idaho 83816</font></p>
                                                            <p><font face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">Phone:<br />
                                                                        208.664.8511</font></p>
                                                            <p><font face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">Fax:<br />
                                                                        208.664.9235 </font></p>
                                                            <p><font face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">
                                                                        <script type="text/javascript">
/*<![CDATA[*/

/***********************************************
* Encrypt Email script- Please keep notice intact
* Tool URL: http://www.dynamicdrive.com/emailriddler/
* **********************************************/
<!-- Encrypted version of: info [at] *******************.*** //-->

var emailriddlerarray=[105,110,102,111,64,105,109,97,103,105,110,97,116,105,111,110,103,114,97,112,104,105,99,115,46,99,111,109]
var encryptedemail_id20='' //variable to contain encrypted email
for (var i=0; i<emailriddlerarray.length; i++)
 encryptedemail_id20+=String.fromCharCode(emailriddlerarray[i])

document.write('<a href="mailto:'+encryptedemail_id20+'">'+encryptedemail_id20+'</a>')

/*]]>*/
</script>
                                                                  </font></p>
                                                      </div>
                                                </td>
                                                <td width="100" height="30">
                                                      <div align="left">
                                                            <font size="-1" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">To<br />
                                                            </font><font size="-2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">[Hold ctrl to select multiple]</font></div>
                                                </td>
                                                <td width="369" height="30"><select id="to" name="to" size="6" multiple="multiple">
                                                            <option value="jeremy@imaginationgraphics.com">Art Department</option>
                                                            <option value="lisa@imaginationgraphics.com">Accounting Department</option>
                                                            <option value="alex@imaginationgraphics.com">Production Department</option>
                                                            <option value="alex@imaginationgraphics.com; lisa@imaginationgraphics.com; matt@imaginationgraphics.com; jeremy@imaginationgraphics.com">Sales Department</option>
                                                            <option value="alex@imaginationgraphics.com; lisa@imaginationgraphics.com; matt@imaginationgraphics.com; jeremy@imaginationgraphics.com">All Departments</option>
                                                      </select></td>
                                          </tr>
                                          <tr height="30">
                                                <td width="100" height="30"><font size="2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">Name</font></td>
                                                <td width="369" height="30"><input type="text" id="name" name="name" size="54" /></td>
                                          </tr>
                                          <tr height="30">
                                                <td width="100" height="30"><font size="2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">Phone</font></td>
                                                <td width="369" height="30"><input type="text" id="phone" name="phone" size="54" /></td>
                                          </tr>
                                          <tr height="30">
                                                <td width="100" height="30"><font size="2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">E-mail</font></td>
                                                <td width="369" height="30"><input type="text" id="email" name="email" size="54" /></td>
                                          </tr>
                                          <tr height="218">
                                                <td valign="top" width="100" height="218"><font size="2" face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif">Comments</font></td>
                                                <td align="left" valign="top" width="369" height="218">
                                                      <div align="left">
                                                            <textarea name="comments" rows="9" cols="51" wrap="physical"></textarea>
                                                            <table width="369" border="0" cellspacing="2" cellpadding="4">
                                                                  <tr>
                                                                        <td></td>
                                                                        <td></td>
                                                                        <td>
                                                                              <div align="right">
                                                                                    <input type="submit" name="Submit" value="Submit" /></div>
                                                                        </td>
                                                                  </tr>
                                                            </table>
                                                      </div>
                                                </td>
                                          </tr>
                                    </table>
                              </form>

Here is the php code i am using to process the form:
<?php
// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$to = addslashes($_POST['to']);
@$name = addslashes($_POST['name']);
@$phone = addslashes($_POST['phone']);
@$email = addslashes($_POST['email']);
@$comments = addslashes($_POST['comments']);

//Sending Email to form owner
$pfw_header = "From: $email\n"
  . "Reply-To: $email\n";
$pfw_subject = "Contact Form";
$pfw_email_to = "$to\n";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "name: $name\n"
. "phone: $phone\n"
. "email: $email\n"
. "comments: $comments\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

header("Location: thankyou.html");

?>
0
Comment
Question by:twistedindustries
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 20282396
When you use a select multiple, the values are stored as an array.  You need to process the array and loop through it to send one email per element in the array.
0
 
LVL 4

Expert Comment

by:rschoenbach
ID: 20282485
this variable (@$to = addslashes($_POST['to']);) will be stored as an array when it posts.

Therefore you need to iterate through it before sending to get your email string.

foreach($_POST['to'] as $email) {
$cleanvalue = addslashes($email);
$email_string .= $cleanvalue
}

Then send the email using $email_string.

Also, since you have activated selecting multiples it would be good practice and would save some lines of code if you added ";" to all the email options.

0
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20282502
change your combobox values separator from ";" to "," and you should be alright:
like this:

<option value="alex@imaginationgraphics.com, lisa@imaginationgraphics.com, matt@imaginationgraphics.com, jeremy@imaginationgraphics.com">Sales Department</option>
                                                            <option value="alex@imaginationgraphics.com, lisa@imaginationgraphics.com, matt@imaginationgraphics.com, jeremy@imaginationgraphics.com">All Departments</option>

The mail() function's TO field with multiple recipients need to be separated by commas.

Hope this helps.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question