|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Email feedback form with address options
Good day. Can anyone please show this PHP beginner how to write the code for a feedback form that will send form results to different addresses depending upon options selected in the form. I have used radio buttons in the form to ask visitors to select the category of their enquiry and then I have tried to send the result to different email addresses by using IF and ELSE IF statements based on the radio button selections. But all I am succeeding in achieving is getting all results (irrespective of radio button selection) sent to the first email address I specify.
|
|
#2
|
|||||
|
|||||
|
RE: Email feedback form with address options
heres mine, I've edited it to kinda suit ur needs,it should give you an idea
php Code:
|
|
#3
|
|||
|
|||
|
RE: Email feedback form with address options
Thanks russ
Your code makes sense to me. I now see how the addy variable is the key. But when I try it out I get this error message: Parse error: parse error in /home/virtual/site139/fst/var/www/html/mailoptions.php on line 7 This is the page I am trying to test: <html> <head> <title>form experiment</title> </head> <body> <?PHP if($_POST[name]Â*!=Â*""Â*&&Â*$_POST[email]Â*!=Â*""Â*&&Â*$_POST[msg]Â*!=Â*""){ $msgÂ*.=Â*"$_POST[msg]nn"; $recipientÂ*=Â*"$_POST[addy]"; $subjectÂ*=Â*"From My Site"; $mailheadersÂ*=Â*"From:Â*$_POST[name]Â*<$_POST[email]>Â*n"; $mailheadersÂ*.=Â*"Reply-To:Â*$_POST[email]nn"; mail($recipient,Â*$subject,Â*$msg,Â*$mailheaders); echoÂ*"<br><br><b>Thank you!</b>n"; } else{ echoÂ*"<b>All fields are required</b><br><br>n"; ?> <form method="post" action="<?=$PHP_SELF?>"> Name: <input type="text" name="name" size="10"; maxlength="50" class="textbox"> <br>Email: <input type="text" name="email" size="10"; maxlength="50" class="textbox"> <br> <select name="addy" class="dropdown"> <option value="valvil@global.co.za">Val</option> <option value="amviljoe@global.co.za">Andre</option> </select> <br><textarea name="msg" cols=40 rows=8></textarea> <br><input type="submit" value="Submit" class="button"> <input type="reset" class="button"> </form> <?php } ?> </body> </html> _________________ To my untrained eyes it looks ok. Can you spot my error? There are 2 elements of your code which I don't understand. They are: the . after $msg and the . after the second $mailheaders. Thanks. <html> <head> <title>form experiment</title> </head> <body> <?PHP if($_POST[name]Â*!=Â*""Â*&&Â*$_POST[email]Â*!=Â*""Â*&&Â*$_POST[msg]Â*!=Â*""){ $msgÂ*.=Â*"$_POST[msg]nn"; $recipientÂ*=Â*"$_POST[addy]"; $subjectÂ*=Â*"From My Site"; $mailheadersÂ*=Â*"From:Â*$_POST[name]Â*<$_POST[email]>Â*n"; $mailheadersÂ*.=Â*"Reply-To:Â*$_POST[email]nn"; mail($recipient,Â*$subject,Â*$msg,Â*$mailheaders); echoÂ*"<br><br><b>Thank you!</b>n"; } else{ echoÂ*"<b>All fields are required</b><br><br>n"; ?> <form method="post" action="<?=$PHP_SELF?>"> Name: <input type="text" name="name" size="10"; maxlength="50" class="textbox"> <br>Email: <input type="text" name="email" size="10"; maxlength="50" class="textbox"> <br> <select name="addy" class="dropdown"> <option value="valvil@global.co.za">Val</option> <option value="amviljoe@global.co.za">Andre</option> </select> <br><textarea name="msg" cols=40 rows=8></textarea> <br><input type="submit" value="Submit" class="button"> <input type="reset" class="button"> </form> <?php } ?> </body> </html> |
|
#4
|
|||
|
|||
|
RE: Email feedback form with address options
I have no idea mate, I can't see anything wrong with it, the . are on my one and it seems to work fine. I dunno what to say, I'm pretty new to PHP myself.
|
|
#5
|
|||
|
|||
|
RE: Email feedback form with address options
Well I think there is a mistake in the syntax on line 7 (surprise?). Actually the $_POST variable is an associative array, thus to access it's element with the key 'name' you should use $_POST["name"] or $_POST['name'], and not $_POST[name], as it is written in your code.
|
|
#6
|
|||
|
|||
|
RE: Email feedback form with address options
Hi Nemesis.
I have tried changing line 7 to Code:
if($_POST["name"]Â*!=Â*""Â*&&Â*$_POST["email"]Â*!=Â*""Â*&&Â*$_POST["msg"]Â*!=Â*""){
I also tried with 'name' etc. Can you spot anything else wrong in line 7? |
|
#7
|
|||
|
|||
|
RE: Email feedback form with address options
|
|
#8
|
|||
|
|||
|
RE: Email feedback form with address options
Also what version of PHP are you running?
From php.net (refering to $_POST): Note: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_VARS. |
|
#9
|
|||
|
|||
|
RE: Email feedback form with address options
I think it's okay with the PHP version, it would say 'undefined variable', not the 'parse error'.
Funny thing is that I do not get any error message, except the predictable 'undefined offset' notice... |
|
#10
|
|||
|
|||
|
RE: Email feedback form with address options
Thanks all. I have now solved the problem.
Now I am looking for the code to store the form results on a designated page on the site. Can anyone help? |
|
#11
|
|||
|
|||
|
RE: Email feedback form with address options
So, where was the problem?
|
|
#12
|
|||
|
|||
|
RE: Email feedback form with address options
Hi nemesis. Well EvilivE's suggestion for line 7 did parse but then there was a parsing problem elsewhere. So I decided to revert to a simple form format that was working for me on another site and to incorporate the dropdown and associated code that russ first suggested to solve my multiple address option problem. And it works, which is good enough for me at this stage of the journey.
But I still need help with that store results on a page thingy. Any suggestions? |
|
#13
|
|||
|
|||
|
RE: Email feedback form with address options
Well, could you specify the problem more precisely? As far as I understand you want to be able store the form contents somewhere. This is easily done by storing the key and values of the $_POST (or $_GET, depends on the form's submission method) variable. E.g.,
Code:
<?php
//storing the form contents into a text file
//while arranging them into a html table
//opening the destination file
$out = fopen ('form_contents.html', 'wt');
//outputting the header
fputs ($out, '<html><head><title>Form contents</title></head><body><table><tr><td><b>Keys</b></td><td><b>Values></b></td></tr>');
//outputting the $_POST contents
foreach ($_POST as $key => $value) {
fputs ($out, '<tr><td>' . $key . '</td><td>' . $value . '</td></tr>');
}
//outputting the footer
fputs ($out, '</table></body></html>');
//closing file
fclose ($out);
?>
|
|
#14
|
|||
|
|||
|
RE: Email feedback form with address options
Thanks again. That storing code looks promising. I have to travel on business today, so I will look at it when I get back. I'll let you know what happens.
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Email feedback form with address options |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|