PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old July 21st, 2002, 07:09 PM
Andre Andre is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Port Elizabeth, South Africa
Posts: 6 Andre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old July 21st, 2002, 09:00 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via AIM to russ Send a message via Yahoo to russ
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:
Original - php Code
  1.  
  2. <?PHP
  3. if($_POST[name] != "" && $_POST[email] != "" && $_POST[msg] != ""){
  4.  
  5. $msg .= "$_POST[msg]nn";
  6.  
  7. $recipient = "$_POST[addy]";
  8. $subject = "From My Site";
  9.  
  10. $mailheaders = "From: $_POST[name] <$_POST[email]> n";
  11. $mailheaders .= "Reply-To: $_POST[email]nn";
  12.  
  13. mail($recipient, $subject, $msg, $mailheaders);
  14. echo "<br><br><b>Thank you!</b>n";
  15.  
  16. }
  17.  
  18. else{
  19. echo "<b>All fields are required</b><br><br>n";
  20. ?>
  21. <form method="post" action="<?=$PHP_SELF?>">
  22. Name: <input type="text" name="name" size="10"; maxlength="50" class="textbox">
  23.  
  24. <br>Email: <input type="text" name="email" size="10"; maxlength="50" class="textbox">
  25.  
  26. <br>
  27. <select name="addy" class="dropdown">
  28. <option value="mail1@server.com">Name</option>
  29. <option value="mail2@server.com">Name</option>
  30. </select>
  31.  
  32. <br><textarea name="msg" cols=40 rows=8></textarea>
  33.  
  34.  
  35.  
  36.  
  37. <br><input type="submit" value="Submit" class="button"> <input type="reset" class="button">
  38. </form>
  39. <?php
  40. }
  41. ?>

Reply With Quote
  #3  
Old July 21st, 2002, 10:52 PM
Andre Andre is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Port Elizabeth, South Africa
Posts: 6 Andre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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>

Reply With Quote
  #4  
Old July 22nd, 2002, 12:31 AM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via AIM to russ Send a message via Yahoo to russ
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.

Reply With Quote
  #5  
Old July 22nd, 2002, 02:38 AM
nemesis nemesis is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Saint-Petersburg, Russia
Posts: 29 nemesis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old July 22nd, 2002, 06:39 AM
Andre Andre is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Port Elizabeth, South Africa
Posts: 6 Andre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Email feedback form with address options

Hi Nemesis.
I have tried changing line 7 to
Code:
if($_POST["name"]Â*!=Â*""Â*&&Â*$_POST["email"]Â*!=Â*""Â*&&Â*$_POST["msg"]Â*!=Â*""){
but I still get the same error.
I also tried with 'name' etc.

Can you spot anything else wrong in line 7?

Reply With Quote
  #7  
Old July 22nd, 2002, 07:19 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to EvilivE
RE: Email feedback form with address options

I would try this:
php Code:
Original - php Code
  1. if(!empty($_POST["name"]) && !empty($_POST["email"]) && !empty($_POST["msg"])){


HTH

Reply With Quote
  #8  
Old July 22nd, 2002, 07:22 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to EvilivE
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.

Reply With Quote
  #9  
Old July 22nd, 2002, 12:08 PM
nemesis nemesis is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Saint-Petersburg, Russia
Posts: 29 nemesis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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...

Reply With Quote
  #10  
Old July 22nd, 2002, 02:16 PM
Andre Andre is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Port Elizabeth, South Africa
Posts: 6 Andre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #11  
Old July 22nd, 2002, 03:02 PM
nemesis nemesis is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Saint-Petersburg, Russia
Posts: 29 nemesis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Email feedback form with address options

So, where was the problem?

Reply With Quote
  #12  
Old July 22nd, 2002, 06:32 PM
Andre Andre is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Port Elizabeth, South Africa
Posts: 6 Andre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?



Reply With Quote
  #13  
Old July 22nd, 2002, 07:04 PM
nemesis nemesis is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Saint-Petersburg, Russia
Posts: 29 nemesis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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);

?>

Reply With Quote
  #14  
Old July 23rd, 2002, 06:01 AM
Andre Andre is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Port Elizabeth, South Africa
Posts: 6 Andre User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Email feedback form with address options


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT