Log in

View Full Version : PHP Mailing Different People



lesham
10-30-2006, 06:55 PM
Hello people,

I would like to say thank you to all of you that are providing scripts and answers to questions here on the forums. I have a question, or a challenge as some of you may take it. I started using PHP a few days ago for this company I work for. They have a contact us page that has 2 drop down lists. One of them are :

I am a/an :
"Prospective insured"
"Prospective agent"
"Insured"
"Agent"
"Uknown Person"

I wish to :
"Request Claim Information"
"Request information about my policy"
"Request information about obtaining my policy"
"Request my password"
"Comment on your website"
"Contact you on an unlisted topic"

These are the two drop downs included in the html form. When the user submits, it sends an email using php to mail a specfic user inlcuding all the information selected/inputted into the form.
The thing I need done is for when they select something under Drop Down 1, and then something from Drop Down 2, i need it to mail to a specific email based on the choises in the drop down.
I started to make arrays and what not but I just cant follow. Is it possible for someone to post a script that will do something like this, or atleast post me the building blocks that I can easily alter to get this form to work properly?

ItsMeOnly
10-30-2006, 07:32 PM
<?
/* The skeleton */

$who = $_POST['who'];
$typeOfInfo = $_POST['typeOfInfo'];

$nameOfWho = array(
"pinsured" => "Prospective insured",
"pagent" => "Prospective agent",
"insured" => "Insured",
"agent" => "Agent",
"unknown" => "Uknown Person");

$nameOfInfo = array(
"Request Claim Information",
"Request information about my policy",
"Request information about obtaining my policy",
"Request my password",
"Comment on your website",
"Contact you on an unlisted topic");


$list = array(
"john.doe@mail.com",
"Homer.Sexual@moes.com",
"trustno1@aol.com"
); /* for gathering addresses of interested parties */

switch ($who) {
case "pinsured" :
$mailing = "$list[0], $list[3]";
break;
case "insured" :
$mailing = $list[2];
break;
/* blah, blah, blah so on, so forth */
default:
die("You should select who you are");
}

$post = "$name, a ". $nameOfWho[$who].
" wants to ". $nameOfInfo[$typeOfInfo] .
":
Additional comment was:
$comment\n";

mail($mailing,
"An information requested",
$post) or die("Mail session failed! The query was not sent, contact the administrator");
?>

lesham
10-30-2006, 08:01 PM
The user selects something out of the drop downs but gets you should sleect who you are. What is the cause of this?

ItsMeOnly
10-30-2006, 08:18 PM
im not following the whole switch part... i put it out there how it is, and tested it to see what i was working with and it said "You should select who you are" but i did select. feel like helping me out some more?
The idea will work if you have form ready, will not work if you don't

<FORM action="myscript.php" method="post">
<SELECT NAME="who">
<OPTION VALUE="pinsured">Prospective insured</option>
<OPTION VALUE="pagent">Prospective agent</option>
<OPTION VALUE="insured">Insured</option>
<OPTION VALUE="agent">Agent</option>
<OPTION VALUE="unknown" selected="selected">Uknown Person</option>
</SELECT>
<select name="typeOfInfo">
<OPTION VALUE="0">Request Claim Information</option>
<OPTION VALUE="1">Request information about my policy</option>
<OPTION VALUE="2">Request information about obtaining my policy</option>
<OPTION VALUE="3">Request my password</option>
<OPTION VALUE="4">Comment on your website</option>
<OPTION VALUE="5">Contact you on an unlisted topic</option>
</select>
<input type="submit" value="Send query">
</form>

lesham
10-30-2006, 08:26 PM
Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\Inetpub\wwwroot\contactus.php on line 57
Mail session failed! The query was not sent, contact the administrator

know what this is from?

line 57= $post) or die("Mail session failed! The query was not sent, contact the administrator");

ItsMeOnly
10-30-2006, 08:58 PM
It means that you didn't read installation notes :-p


but seriously, you need to set several defaults in your php installation, creating a php.ini file- you can also add 4th parameter to mail(), which is "From: me@mydomain.net"

lesham
10-30-2006, 09:01 PM
This code is great, works effectively, but... What im trying to do is to form a matrix of some sort, i want a combination of selections, like if i was a pinsured who chose password, i want it to go to a support team, but if i was a pinsured who chose request claim information, i want it to send elsewhere... u know? it seems it only sends to just the first drop down entry, not a combination...

p.s. the issue i had before was fixed, damn ; (commented out)

ItsMeOnly
10-30-2006, 09:25 PM
What im trying to do is to form a matrix of some sort
That's where case comes in, if you wanna build on type of support, you'll need change switch() parameter to $typeOfInfo, and rebuild cases. You will have 6 (from 0 and 5) cases /and default, if needed/.

You can combine case, like


case 1 :
case 2 :
$mailing = "$list[2], $list[3]";
break;
case 3 :
$mailing = $list[0];
break;

lesham
10-30-2006, 09:29 PM
Well i suppose i get what you are saying, although it seems like its one or the other and not both. Either send an email based on who it is , or what type of info. I do not have the current emails that are going to be used for this, maybe the emails will be simple enough that i can send them based on the type of info. If not, im going to have to find an alternative way to do this. Thanks alot for the help, i have been plugging away at this for a week haha

ItsMeOnly
10-30-2006, 09:52 PM
Well i suppose i get what you are saying, although it seems like its one or the other and not both. Either send an email based on who it is , or what type of info.
Case inside case, or, external referencing via building a two-dimentional array
containing the "caretakers" for specific groups of clients: basically we're now entering relational databases, but it can be done with just smart programming


$typeOfInfoPeople = array(
/* pinsured, pagents, insured, agents, unknown */
0 => array("$list[0], $list[2]" /* note the parenthesis*/,
NULL, NULL, NULL, NULL),
1 => array(NULL, $list[2], NULL, NULL, NULL)
/* etc */
)

Now, to build $mailing, you can just reference the desired element of such "mega array"., like $mailing = $typeOfInfoPeople[$typeOfInfo][$who]. Ah, one thing, the "NULLs" should be verified before trying to mail to no address.
it's best just to
if (!$mailing) die("We apologize. For the moment, we cannot provide feedback for ". $typeOfWho[$who]);
else {
mail()
}

lesham
10-31-2006, 12:02 PM
hmp smart programming ... that would be where you come in. I was thinking and started doing it by making each phrase an array... and then trying to reference it and i was just going all wrong with it. I will try this snippet and let you know how things work out, if i can even figure this out haha.

lesham
10-31-2006, 12:18 PM
If you could, show the complete code from head to toes, that would be great, trying to see what im doing right/wrong.

ItsMeOnly
10-31-2006, 01:15 PM
<?
/* The skeleton */

$who = $_POST['who'];
$typeOfInfo = $_POST['typeOfInfo'];

$nameOfWho = array(
1 => "Prospective insured",
"Prospective agent",
"Insured",
"Agent",
"Uknown Person"
);

$nameOfInfo = array(
1 => "Request Claim Information",
"Request information about my policy",
"Request information about obtaining my policy",
"Request my password",
"Comment on your website",
"Contact you on an unlisted topic"
);

$list = array(
"john.doe@mail.com",
"Homer.Sexual@moes.com",
"trustno1@aol.com",
"foo@bar.com",
"blah@the.net",
"president@whitehouse.gov"
);

$typeOfInfoPeople = array(
1=> array("$list[0], $list[2]", NULL, NULL, NULL, $list[5]),
array($list[1], $list[2], NULL, NULL, NULL, $list[5]),
array(NULL, $list[2], NULL, $list[5], NULL, $list[5]),
array(NULL, NULL, NULL, NULL, NULL, $list[5]),
array(NULL, NULL, list[3], NULL, NULL, $list[5]),
array("$list[0], $list[1]",
"$list[0], $list[2]",
"$list[0], $list[3]",
"$list[0], $list[4]",
"$list[0], $list[5]",
"$list[0], $list[1], $list[2], $list[3], $list[4], $list[5]"
);

$post = "$name, a ". $nameOfWho[$who].
" wants to ". $nameOfInfo[$typeOfInfo] .
":
Additional comment was:
$comment\n";

$mailing = $typeOfInfoPeople[$typeOfInfo][$who];

if (!$mailing)
die("We apologize. For the moment, we cannot provide feedback for ". $typeOfWho[$who]);
else {
mail($mailing,
"An information requested",
$post) or die("Mail session failed! The query was not sent, contact the administrator");
?>

the form will change slightly to simplify variables:

<FORM action="myscript.php" method="post">
<SELECT NAME="who">
<OPTION VALUE="1">Prospective insured</option>
<OPTION VALUE="2">Prospective agent</option>
<OPTION VALUE="3">Insured</option>
<OPTION VALUE="4">Agent</option>
<OPTION VALUE="5" selected="selected">Uknown Person</option>
</SELECT>
<select name="typeOfInfo">
<OPTION VALUE="1">Request Claim Information</option>
<OPTION VALUE="2">Request information about my policy</option>
<OPTION VALUE="3">Request information about obtaining my policy</option>
<OPTION VALUE="4">Request my password</option>
<OPTION VALUE="5">Comment on your website</option>
<OPTION VALUE="6">Contact you on an unlisted topic</option>
</select>
<input type="submit" value="Send query">
</form>

lesham
10-31-2006, 01:23 PM
should something like this work?

lesham
10-31-2006, 01:39 PM
Parse error: parse error, unexpected '[', expecting '(' in C:\Inetpub\wwwroot\contactus.php on line 37

37 = array(NULL, NULL, list[3], NULL, NULL, $list[5]),

ItsMeOnly
10-31-2006, 01:41 PM
find the error, learn

lesham
10-31-2006, 01:44 PM
lol the error, was not on that line at all, it appears that i dont need the {} on the if/else statement, although it says
We apologize. For the moment, we cannot provide feedback for
... and when the emails do send, it only posts
, a Unknown Person wants to Comment on your website:
Additional comment was:

Hmmm...

ItsMeOnly
10-31-2006, 02:40 PM
nope, you only masked the error

lesham
10-31-2006, 02:46 PM
yes, i did figure the error out, but somereason its not posting ne data... does this script work for you?

i tried over n over again and get the We apologize. For the moment, we cannot provide feedback for error...

ItsMeOnly
10-31-2006, 04:23 PM
show me your script and form too

lesham
10-31-2006, 04:40 PM
<?

$who = $_POST['who'];
$typeOfInfo = $_POST['typeOfInfo'];

$nameOfWho = array(
1 => "Prospective insured",
"Prospective agent",
"Insured",
"Agent",
"Unknown Person"
);

$nameOfInfo = array(
1 => "Request Claim Information",
"Request information about my policy",
"Request information about obtaining my policy",
"Request my password",
"Comment on your website",
"Contact you on an unlisted topic"
);

$list = array(
"lesham@farmersosfalem.com",
"lesham@farmersosfalem.com",
"lesham@farmersosfalem.com",
"lesham@farmersosfalem.com",
"lesham@farmersosfalem.com",
"lesham@farmersosfalem.com"
);

$typeOfInfoPeople = array(
1=> array("$list[0], $list[2]", NULL, NULL, NULL, $list[5]),
array($list[1], $list[2], NULL, NULL, NULL, $list[5]),
array(NULL, $list[2], NULL, $list[5], NULL, $list[5]),
array(NULL, NULL, NULL, NULL, NULL, $list[5]),
array(NULL, NULL, NULL, NULL, NULL, $list[5]),
array("$list[0], $list[1]",
"$list[0], $list[2]",
"$list[0], $list[3]",
"$list[0], $list[4]",
"$list[0], $list[5]",
"$list[0], $list[1], $list[2], $list[3], $list[4], $list[5]"
)
);

$post = "$name, a ". $nameOfWho[$who].
" wants to ". $nameOfInfo[$typeOfInfo] .
":
Additional comment was:
$comment\n";

$mailing = $typeOfInfoPeople[$typeOfInfo][$who];

if (!$mailing)
die("We apologize. For the moment, we cannot provide feedback for ". $typeOfWho[$who]);
else
mail($mailing,
"An information requested",
$post) or die("Mail session failed! The query was not sent, contact the administrator");

?>




<form name=contactus method="POST" action="contactus.php" target=_self onsubmit="return formCheck(this);">
<tr><td align="left"><font size="2">First Name</font></td>
<td align="left"><input name="First Name" value size="35" maxlength=16 value=""></td></tr>
<input type="hidden" name="r_Fisrt Name" value="First Name Is Required">
<tr><td align="left" height="24"><font size="2">Last Name</font></td>
<td align="left" height="24"><input type="text" name="Last name" size="35" maxlength=32 value=""></td></tr>

<tr><td align="left"><font size="2">Company</font></td>
<td align="left"><input type="TEXT" name="Company" value size="35" maxlength=32 value=""></td></tr>

<tr><td align="left"><font size="2">Street Address</font></td>
<td align="left"><input type="text" name="Street" size="35" maxlength=32 value=""></td></tr>
<tr><td align="left"><font size="2">City</font></td>
<td align="left"><input type="text" name="City" size="35" maxlength=20 value=""></td></tr>
<tr><td align="left"><font size="2">State</font></td>
<td align="left"><input type="text" name="State" size="35" maxlength=2 value=""></td></tr>
<tr><td align="left"><font size="2">Zip Code</font></td>
<td align="left"><input type="text" name="ZipCode" size="35" maxlength=5 onblur= valzip(); value=""></td></tr>
<tr><td align="left"><font size="2">Policy Number</font></td>
<td align="left"><input type="text" name="Policy" size="35" maxlength=16 value=""></td></tr>
<tr><td align="left"><font size="2">Daytime Phone</font></td>
<td align="left"><input type="TEXT" name="Telephone" value size="35" maxlength=16 value=""></td></tr>
<tr><td align="left"><font size="2">E-mail<br>
<br>
<br>
<br>
<br>
&nbsp;</font></td>
<td align="left"><input type="TEXT" name="Email" value size="35" maxlength=40 value=""><br>
<br>
<br>
<br>
<br>
&nbsp;</td></tr>
</table>
</td>
<td width="303" colspan="2">
<p align="left">


I am a/an :</p></td>
</tr>
<tr>
<td width="303" colspan="2">


<SELECT NAME="who">
<OPTION VALUE="1">Prospective insured</option>
<OPTION VALUE="2">Prospective agent</option>
<OPTION VALUE="3">Insured</option>
<OPTION VALUE="4">Agent</option>
<OPTION VALUE="5" selected="selected">Uknown Person</option>
</SELECT></td>
</tr>
<tr>
<td width="303" colspan="2">
<font size="2">I wish to :
</font></td>
</tr>
<tr>
<td width="303" colspan="2">


<select name="typeOfInfo">
<OPTION VALUE="1">Request Claim Information</option>
<OPTION VALUE="2">Request information about my policy</option>
<OPTION VALUE="3">Request information about obtaining my policy</option>
<OPTION VALUE="4">Request my password</option>
<OPTION VALUE="5">Comment on your website</option>
<OPTION VALUE="6">Contact you on an unlisted topic</option>
</select></td>
</tr>
<tr>
<td width="303" colspan="2">
<font size="2">Message/Question</font> <!--<input type=text name=Comments size=35>--></td>
</tr>
<tr>
<td width="303" colspan="2">
<textarea name="comment" rows="9" cols="50" maxlength=800 value=""></textarea></td>
</tr>
<tr>
<td width="303" colspan="2">
<font size="2">User Verification: 1 + 2 =</font> <input type=text size=2 name=verify></td>
</tr>
<tr>
<td width="63">
<input type="submit" onSubmit="return checkmail(this)" value="Submit" name="B1"></td>
<td width="236">
<input type="reset" value="Cancel" name="B2"></td></form>

ItsMeOnly
10-31-2006, 05:01 PM
While everything is fine, you literally passed out the "nulls", so the script will work in just 7 cases...

lesham
10-31-2006, 05:56 PM
what do you mean? did i miss something?

ItsMeOnly
10-31-2006, 07:49 PM
you wanted to send out to different people, for now it's just one address only, and bunch of nulls

lesham
10-31-2006, 08:08 PM
i want to be able to send an email based on the decision of drop down 1 + drop down 2.... is it possible within this code?

ItsMeOnly
10-31-2006, 09:32 PM
it's not just possible, it's already there, you just need to fillout the twodimensional array (or rather array of arrays) with address strings (and to make things easier, I introduced an array with email addresses so you just need to enter member numbers instead of repeating strings of email addresses).

lesham
10-31-2006, 09:42 PM
ugh now to get it to work, thanks alot, sorry for me being a pain in the ass, i dont do php so well... im more of a C# person but im only 18 and learning