Solved

PHP form submission to multiple emails

Posted on 2007-11-14
3
1,036 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 125 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…

739 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