Forum Moderators: coopster
e.g. when software is selected, then the email will be send to a number of addresses associated with that option.
Here's what i have so far, which just sends one email. can anyone please show me how to solve my problem. thanks!
-------------------------------------------------
-
-
Code:
<td><div align="left">
<select name="typesupport" id="typesupport">
<option selected>--select type--</option>
<option value="hardware">hardware</option>
<option value="software">software</option>
</select>
*</div></td>
-
Thanks!
-
--------------------------------------------------------
PHP Code:
<?php
/*Here we are going to declare the variables*/
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$location = $_POST['location'];
$contactnum = $_POST['contactnum'];
$typesupport = $_POST['typesupport'];
$ipaddress = $_POST['ipaddress'];
$probdesc = $_POST['probdesc'];
$hsolved = $_POST['hsolved'];
//Save visitor name and entered message into one variable:
$subject = "log problem with example";
$formcontent="PROBLEM LOGGED BY ------- $name\n\nCLIENT NAME ------- $company\n\nLOCATION ------- $location\n\nCONTACT NUMBER ------- $contactnum\n\n
TYPE OF SUPPORT ------- $typesupport\n\nIP ADDRESS ------- $ipaddress\n\nDESCRIPTION OF PROBLEM ------- $probdesc\n\nHAS THIS PROBLEM BEEN SOLVED BEFORE? ------- $hsolved";
/*mail header*/
$mailheader = "From: $email\r\n";
$mailheader .= "MIME-Version: 1.0\r\n";
$valid_emails = array("some.person","another.person");
if(in_array($_POST['typesupport'],$valid_emails))
{
$recipient = $_POST['typesupport'] . "@example.co.uk";
mail($recipient, $subject, $formcontent, $mailheader);
echo "mail has been sent";
}
else
{
echo "problems sending the email. Have a word!";
}
?>
[edited by: jatar_k at 4:33 pm (utc) on May 16, 2005]
[edit reason] generalized names and domains [/edit]
<form method=post> <select name="typesupport"> <option />hardware <option />software </select> <input type="submit"> </form> <? $sendto=""; $hard_emails = array("hard.guy","hard.gal"); $soft_emails = array("soft.guy","soft.gal"); $addrs = array("hardware"=>$hard_emails,"software"=>$soft_emails); if ($_POST["typesupport"]) { foreach($addrs as $key => $val) { if ($_POST["typesupport"]==$key) { for($i=0;$i<sizeof($val);$i++) { $sendto.=$val[$i]."@some.uk,"; } } } #REMOVE EXTRA COMMA AT THE END $sendto=substr($sendto,0,-1); #FOR VIEWING RESULT (COPY-AND-PASTE THIS ENTIRE CODE TO TEST) echo "SEND TO: ".$sendto."<br />\n"; } ?> Voila.
i've got a bit further. can anyone help me? thanks
--------------------------------------------
------------
logproblem.php
<select name="typesupport" id="typesupport">
<option selected>--select type--</option>
<option value="hardware">hardware</option>
<option value="software">software</option>
</select> //Save visitor name and entered message into one variable:
$subject = "log problem with microcomputing";
$formcontent="PROBLEM LOGGED BY ------- $name\n\nCLIENT NAME ------- $company\n\nLOCATION ------- $location\n\nCONTACT NUMBER ------- $contactnum\n\n
TYPE OF SUPPORT ------- $typesupport\n\nIP ADDRESS ------- $ipaddress\n\nDESCRIPTION OF PROBLEM ------- $probdesc\n\nHAS THIS PROBLEM BEEN SOLVED BEFORE? ------- $hsolved";
/*mail header*/
$mailheader = "From: $email\r\n";
$mailheader .= "MIME-Version: 1.0\r\n";
$hard_emails = array("name1","name2");
$soft_emails = array("name1","name2");
$addrs = array("hardware"=>$hard_emails,"software"=>$soft_emails);
$confirmed_emails = array();
if ($_POST["typesupport"])
{
foreach($addrs as $key => $val)
{
if($_POST["typesupport"]==$key)
{
for($i=0;$i<sizeof($val);$i++)
{
$confirmed_emails[] = $_POST['typesupport'].'@example.co.uk';
}
}
}
}
if(!empty($confrimed_emails))
{
$recipient = implode (',', $confrimed_emails);
mail($recipient, $subject, $formcontent, $mailheader);
echo "mail has been sent";
}
else
{
echo "problems sending the email.";
}
php>[/PHP]
[edited by: jatar_k at 4:17 pm (utc) on May 19, 2005]
[edit reason] generalized emails [/edit]
$confirmed_emails .= $val[$i]."@example.co.uk,"; and AFTER the loop has completed:
#strip off the trailing comma: $confirmed_emails = substr($confirmed_emails,0,-1); then just use $confirmed_emails instead of needing to implode the array.
Second, if you copy-and-pasted, there's a spelling issue with your mail() attempt:
if(!empty($[b]confrimed[/b]_emails)) { #just use $confirmed_emails instead of $recipient $recipient = implode (',', $[b]confrimed[/b]_emails); mail($recipient, $subject, $formcontent, $mailheader); echo "mail has been sent"; }