Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP form submission to multiple emails

Posted on 2007-11-14
3
Medium Priority
?
1,045 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
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

972 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