Solved

PHP form submission to multiple emails

Posted on 2007-11-14
3
1,035 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 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

828 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