Solved

PHP form submission to multiple emails

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now