Jump to content

Need help with my code for multiple recipients


dhatura1

Recommended Posts

Ok. Let me start by saying i don't know a whole hell of a lot about php. I do alot of flash and html.

Any help would be GREATLY appreciated. I'm just learning the basics still.

Also, the url is sideshowsirens.com/contact.php if anyone wants to look for themselves

 

Problem 1: :confused: :confused: :confused:  :shrug::confused: :confused: :confused:

 

I have a site that i need to change the contact to send emails to different addresses depending on what department they select. Currently sends all emails to all addresses listed.

 

Problem 2:

 

The "mail sent" page used to post info  for "attn" and display whichever dept was selected. now shows up as "attn ()"

 

html code from contact.php:

<td valign="top" width="24%" align="center" height="80"> </td>

<td valign="top" width="33%" height="40">

   </td>

</tr>

 

<tr>

<td valign="middle" width="10%" height="40"> </td>

<td valign="middle" width="24%" align="center" height="40"><font face="Adobe Garamond Pro" size="4" color="white">

  <label for="first">First Name *</label></font>

</td>

 

<td valign="middle" width="33%" height="40">

  <input  type="text" name="first" maxlength="50" size="30">

</td>

</tr>

 

<tr>

<td valign="middle"" width="10%" rowspan="5"> </td>

<td valign="middle"" width="24%" align="center"><font face="Adobe Garamond Pro" size="4" color="white">

  <label for="last">Last Name *</label></font>

</td>

 

<td valign="middle" width="33%">

  <input  type="text" name="last" maxlength="50" size="30">

</td>

</tr>

<tr>

<td valign="top" width="24%" align="center"><font face="Adobe Garamond Pro" size="4" color="white">

  <label for="email">Email Address *</label></font>

</td>

 

<td valign="middle" width="33%">

  <input  type="text" name="visitormail" maxlength="80" size="30">

</td>

</tr>

 

<tr>

<td valign="middle" width="24%" align="center"><font face="Adobe Garamond Pro" size="4" color="white">

  <label for="telephone">Telephone Number</label></font>

</td>

<td valign="middle" width="33%">

  <input  type="text" name="telephone" maxlength="30" size="30">

</td>

</tr>

 

<tr>

<td valign="middle" width="24%" align="center"><font face="Adobe Garamond Pro" size="4" color="white">

  <label for="reason">Reason for contacting us *</label></font>

</td>

 

<td valign="middle" width="33%">

  <select name="emailaddress" id="emailaddress">

 

<option value="1" selected="selected">Booking</option>

<option value="1">More info</option>

<option value="1" >Show dates</option>

<option value="1">Other</option>

<option value="0">Webmaster</option>

 

</select> </td>

</tr>

 

<tr>

<td valign="top" width="24%" align="center"><font face="Adobe Garamond Pro" size="4" color="white">

  <label for="comments">Message *</label></font>

</td>

<td valign="top" width="33%">

  <textarea  name="notes" maxlength="1000" cols="21" rows="6"></textarea>

</td>

</tr>

 

<tr>

<td colspan="2" style="text-align:center" height="47"> </td>

<td colspan="2" style="text-align:center" height="47">

  <input type="submit" value="Submit"> 

<p> </td>

</tr>

<tr>

<td colspan="2" style="text-align:center" height="21"> 

  </td>

<td colspan="2" style="text-align:center" height="21">

   </td>

</tr>

</table>

 

</form>

 

php mailer code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Sendemail Script</title>

</head>

<body>

 

<?php

 

$ip = $_POST['ip'];

$httpref = $_POST['httpref'];

$httpagent = $_POST['httpagent'];

$visitor = $_POST['visitor'];

$visitormail = $_POST['visitormail'];

$notes = $_POST['notes'];

$attn = $_POST['attn'];

 

 

 

if (eregi('http:', $notes)) {

die ("Do NOT try that! ! ");

}

if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))

{

echo "<h2>Use Back - Enter valid e-mail</h2>\n";

$badinput = "<h2>Your message was not sent</h2>\n";

echo $badinput;

die ("Go back! ! ");

}

 

if(empty($visitormail) || empty($notes )) {

echo "<h2>Use Back - Please complete all fields</h2>\n";

die ("");

}

 

 

$todayis = date("l, F j, Y, g:i a") ;

 

$attn = $attn ;

$subject = $attn ;

 

$notes = stripcslashes($notes);

 

$message = " $todayis [EST] \n

Attention: $attn \n

Message: $notes \n

From: $visitor ($visitormail)\n

Additional Info : IP = $ip \n

Browser Info: $httpagent \n

Referral : $httpref \n

";

 

$from = "From: $visitormail\r\n";

mail("[email protected]", $subject, $message, $from);

mail("[email protected]", $subject, $message, $from);

 

 

 

 

 

$emailaddress = array();

 

$emailaddress[0] = "[email protected]" ;

    $emailaddress[1] = "[email protected]" ;

 

 

 

 

 

 

 

 

?>

 

<p align="center">

Date: <?php echo $todayis ?>

<br />

Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )

<br />

 

Attention: <?php echo $attn ?> ( <?php echo $attn ?> )

<br />

Message:<br />

<?php $notesout = str_replace("\r", "<br/>", $notes);

echo $notesout; ?>

<br />

<?php echo $ip ?>

 

<br /><br />

<a href="thankyou.html"> Next Page </a>

</p>

 

</body>

</html>

 

 

Is it only the 2 email addresses in the code that need to be selected from? If so, you can use this, or something similar. Hope this makes sense, it's past my bed time . . .

 

$mail_index = (int) $_POST['emailaddress'];

// Each index coincides with an <option></option> value in the <select> list
$emailaddress = array(
0 => "[email protected]", 
1 => "[email protected]"
);

$to = $emailaddress[$mail_index];

mail($to, $subject, $message, $from);

ok. Problem no. 1 solved. But im still stuck with problem 2.

I got the multiple recipients working. Thank you Pikachu2000.

the second problem is that since i had to use array() to show the multiple recipients it now shows on the "message sent" confirmation page that the "attn:" of the message is array(array)

how can i get this back to showing the receiving department?

 

 

heres my php code:

 

 

 

$todayis = date("l, F j, Y, g:i a") ;

 

$attn = $attn ;

$subject = $attn ;

 

$notes = stripcslashes($notes);

 

$message = " $todayis [EST] \n

Attention: $attn \n

Message: $notes \n

From: $visitor ($visitormail)\n

Additional Info : IP = $ip \n

Browser Info: $httpagent \n

Referral : $httpref \n

";

 

$from = "From: $visitormail\r\n";

$mail_index = (int) $_POST['attn'];

 

$attn = array(

booking => "[email protected]",

info => "[email protected]",

dates => "[email protected]",

webmaster => "[email protected]",

other => "[email protected]"

);

 

$to = $attn[$mail_index];

 

mail($to, $subject, $message, $from);

 

 

 

 

?>

 

<p align="center">

Date: <?php echo $todayis ?>

<br />

Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )

<br />

 

Attention: <?php echo $attn ?> ( <?php echo $attn ?> )

<br />

Message:<br />

<?php $notesout = str_replace("\r", "<br/>", $notes);

echo $notesout; ?>

<br />

<?php echo $ip ?>

 

<br /><br />

<a href="thankyou.html"> Next Page </a>

</p>

 

Also, when i receive the email in my inbox the subject is "0"

sorry wrong php code this is the correct code:

 

$todayis = date("l, F j, Y, g:i a") ;

 

$attn = $attn ;

$subject = $attn ;

 

$notes = stripcslashes($notes);

 

$message = " $todayis [EST] \n

Attention: $attn \n

Message: $notes \n

From: $visitor ($visitormail)\n

Additional Info : IP = $ip \n

Browser Info: $httpagent \n

Referral : $httpref \n

";

 

$from = "From: $visitormail\r\n";

$mail_index = (int) $_POST['attn'];

 

$attn = array(

 

1 => "[email protected]",

0 => "[email protected]"

);

 

$to = $attn[$mail_index];

 

mail($to, $subject, $message, $from);

 

 

 

 

?>

 

<p align="center">

Date: <?php echo $todayis ?>

<br />

Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )

<br />

 

Attention: <?php echo $attn ?> ( <?php echo $attn ?> )

<br />

Message:<br />

<?php $notesout = str_replace("\r", "<br/>", $notes);

echo $notesout; ?>

<br />

<?php echo $ip ?>

 

<br /><br />

<a href="thankyou.html"> Next Page </a>

</p>

 

Just need to set you up with a way to determine what department to display, based on the <select>ion made. There a re few places you'll need to edit to make this echo things the way you want it to. I marked those with comments in the code.

 

<?php
$todayis = date("l, F j, Y, g:i a") ;
$subject = 'SUBJECT'; // CHANGE ME!!!
$notes = stripcslashes($notes);
$from = "From: $visitormail\r\n";
$mail_index = (int) $_POST['attn'];

$attn = array(
1 => "[email protected]",
0 => "[email protected]"
);

if( $mail_index == 0 ) {
$dept = "INSERT_FIRST_DEPARTMENT_NAME_HERE";  // CHANGE ME TOO !!!
}

if( $mail_index == 1 ) {
$dept = "INSERT_SECOND_DEPARTMENT_NAME_HERE";  // AND ME !!
}

$to = $attn[$mail_index];
$message = " $todayis [EST] \n
Attention: $dept \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";
mail($to, $subject, $message, $from);
?>

<p align="center">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

Attention: <?php echo $dept ?> ( <?php echo $attn[$mail_index] ?> )
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>

<br /><br />
<a href="thankyou.html"> Next Page </a>
</p>

awesome. Thank you very much. Works like a charm. When you get a chance, check out the rest of the site and lemme know what you think. I not only built the site, I am one of the mc's and trainers. Have been training these girls for 2 years now.

 

http://sideshowsirens.com

 

Once I have the legal page up giving credits to everyone(photographers, videographer, web designer, etc...) I will make sure to put in a word for you for your php help. Do you have a site i can link it to or a portfolio online? and  should i use pikachu or another name?

I'm working on another site, but it isn't ready. In fact, I haven't even registered the domain name for it yet . . . I honestly appreciate the offer, but really I don't have a portfolio or anything like that. I currently just write code for my own projects and help others out when I can.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.