Page 1 of 1

Help php mail function PROBLEM - adding 2 email addresses

Posted: Sat Oct 03, 2009 7:35 pm
by stanskywalker
i have two email addresses in the php code lets say they are the same email address. When its the same email adddress the code works fine,i recieve both emails....my problem is having two different email addresses in the php code, when the form is submitted i recieve only the one email, cant figure it out...i have two files emailcomfirm.php and the one below you can feel free to copy the code as you wish and upload to server and test for yourself.

if anyone can help with this matter.. i would be most grateful.

Thankyou.

here is the php code.

<html>
<form action="workingContactForm(2).php" name="doublecombo" method="post">
<table cellpadding="2" cellspacing="0" border="0">
<tr valign="top" align="left">
<td>Name:</td>
<td><input type="text" name="name" size="30" maxlength="100" value="<?php if(isset($_POST['name'])) echo $_POST['name']; ?>" /></td>
</tr>
<tr valign="top" align="left">
<td>Email:</td>
<td><input type="text" name="email" size="30" maxlength="100" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /></td>
</tr>
<tr valign="top" align="left">
<td>Type of Service:</td>
<td>
<select name="serviceType" size="1" onChange="redirect(this.options.selectedIndex)">
<option value="Technology Sites">Technology Sites</option>
<option value="News Sites">News Sites</option>
<option value="Search Engines">Search Engines</option>
</select></td>
</tr>
<tr valign="top" align="left">
<td>Type of Pet:</td>
<td>
<select name="petType" size="1">
<option value="http://javascriptkit.com">JavaScript Kit</option>
<option value="http://www.news.com">News.com</option>
<option value="http://www.wired.com">Wired News</option>
</select></td>
</tr>
<tr valign="top" align="left">
<td>Weight:</td>
<td>
<select name="weight" id="weight">
<option value=0></option>
<option value="m">m</option>
<option value="t">t</option>
<option value="tn">tn</option>
</select>
<br /></td>
</tr>
<tr valign="top" align="left">
<td>Amount</td>
<td><input type="text" name="amount" size="30" maxlength="100" value="<?php if(isset($_POST['amount'])) echo $_POST['amount']; ?>" /></td>
</tr>
<tr valign="top" align="left">
<td>Subject:</td>
<td><input type="text" name="subject" size="30" maxlength="100" value="<?php if(isset($_POST['subject'])) echo $_POST['subject']; ?>" /></td>
</tr>
<tr valign="top" align="left">
<td>Message:</td>
<td><textarea name="message" cols="70" rows="10"><?php if(isset($_POST['message'])) echo $_POST['message']; ?></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" width="125px" value="Send Email" onclick="this.disabled = true;form.submit()"/>
<input type="hidden" name="submitted" value="TRUE" />
<script>
<!--

/*
Double Combo Script Credit
By JavaScript Kit (http://www.javascriptkit.com)
Over 200+ free JavaScripts here!
*/

var groups=document.doublecombo.serviceType.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group=new Array()

group[0][0]=new Option("JavaScript Kit","http://javascriptkit.com")
group[0][1]=new Option("News.com","http://www.news.com")
group[0][2]=new Option("Wired News","http://www.wired.com")

group[1][0]=new Option("CNN","http://www.cnn.com")
group[1][1]=new Option("ABC News","http://www.abcnews.com")

group[2][0]=new Option("Hotbot","http://www.hotbot.com")
group[2][1]=new Option("Infoseek","http://www.infoseek.com")
group[2][2]=new Option("Excite","http://www.excite.com")
group[2][3]=new Option("Lycos","http://www.lycos.com")

var temp=document.doublecombo.petType

function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options=new Option(group[x].text,group[x].value)
}
temp.options[0].selected=true
}

function go(){
location=temp.options[temp.selectedIndex].value
}

//-->
</script></td>
</tr>
</table>
</form>
<?php
// Check for form submission
if (isset($_POST['submitted']))
{
/*
The scrubber function takes a string argument and returns a "clean" version of the string
- removing any potentially harmful elements
*/
function spamScrubber($value)
{
// List of string elements to look for
$badStuff = array('to:', 'cc:', 'bcc:', 'content-type:', 'mime-version:', 'multipart-mixed:', 'content-transfer-encoding:');


// Look for any of the bad strings in the message and replace with an empty string
foreach ($badStuff as $v)
{
if(stripos($value, $v) !== false) return '';
}

// Replace any newline characters with a space
$value = str_replace(array("\r", "\n", "%0a", "%0d"), ' ', $value);

// Return the cleaned up $value
return trim($value);
} // End of spamScrubber function

// Clean anything entered in the form
$cleaned = array_map('spamScrubber', $_POST);

// Check that all fields are filled out
if (!empty($cleaned['email']))
{
// Validate the email address
if (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $_REQUEST['email']))
{
// Email address checks out, check that name and comments fields are filled out
//
if (!empty($cleaned['name']) &&
!empty($cleaned['weight']) &&
!empty($cleaned['amount']) &&
!empty($cleaned['serviceType']) &&
!empty($cleaned['petType']) &&
!empty($cleaned['subject']) &&
!empty($cleaned['message']))
{
// Create the body of the email

$body = "Name: {$cleaned['name']}
Service Type: {$cleaned['serviceType']}
Pet Type: {$cleaned['petType']}
Weight: {$cleaned['weight']}
Amount: {$cleaned['amount']}
Message: {$cleaned['message']}";

// Restrict lines to 70 characters
$body = wordwrap($body, 70);

// Send the email
mail('mail@email.com', "{$cleaned['subject']}", $body, "From: {$cleaned['email']}");
mail('mail@email.com', "{$cleaned['subject']}", $body, "From: {$cleaned['email']}");


$replyName=$cleaned['name'];
$replyEmail=$cleaned['email'];
// Change MY COMPANY as appropriate
$replySubject="Auto-response from: Greenwich Trade Corporation";
$replyServiceType=$cleaned['serviceType'];
$replyPetType=$cleaned['petType'];
$replyWeight=$cleaned['weight'];
$replyAmount=$cleaned['amount'];
$replyMessage=$cleaned['message'];
$replyDate=date('l F j\, Y');
// Leave the following lines on the left margin so it aligns right in the emails sent to the addresses
$replyAutoResponse="***This is an automated reply.***

Thank you for contacting us, $replyName. The message you sent on $replyDate follows:
_________________________________________________________________________________

$replyMessage
_________________________________________________________________________________

We will reply to your message as soon as possible.

Have a great day, $replyName!";

mail($replyEmail, $replySubject, $replyAutoResponse);



echo '<meta http-equiv="refresh" content="0;url=http://www.ibuylogos.com/emailConfirm.php">';

// Clear $_POST to prevent the form from re-displaying upon successful submission
$_POST = array();
}
else
{
echo '<div align="center"><p class="error">Please fill out the form completely.</p></div>';
}
}
else
{
echo '<div align="center"><p class="error">The email address you entered is not in the correct format.</p></div>';
}
}
else
{
echo '<div align="center"><p class="error">Please fill out the form completely.</p></div>';
}
}
?>