php mail form issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adriscoll
Forum Newbie
Posts: 1
Joined: Sat Mar 12, 2011 9:52 am

php mail form issue

Post by adriscoll »

Hello.

I have a mail form (volunteer_send) for a site administrator to contact people associated with a certain activity (identified by the event_id variable). The variable is passed via URL from a preceeding page (as a variable called 'id'). I have spent crazy hours trying to figure out if i have a syntax error or something because I cannot get the variable to pass. If I hard code the id in the select statement, then it works fine.

Also, I changed the syntax of the select statement to event_id = event_id and it emailed everyone in the list while I was testing. woops.

any insight would be great.

Code: Select all

<?php

include('dbconfig.php');

// Make a MySQL Connection
mysql_connect("localhost", "$user", "$password") or die(mysql_error());
mysql_select_db("$database") or die(mysql_error());

$adminmail="event@xxxxxxxxx.com";
// Pass the event id variable
$event_id=$_GET['id'];

if(isset($_POST['submit']))
{
  $subject=$_POST['subject'];
  $nletter=$_POST['nletter'];
  if(strlen($subject)<1)
  {
     print "You did not enter a subject.";
  }
  else if(strlen($nletter)<1)
  {
    print "You did not enter a message.";
  } 
  else
  {
	  
     $nletter=$_POST['nletter'];
      $subject=$_POST['subject'];
      $nletter=stripslashes($nletter);
      $subject=stripslashes($subject);
      $lists=$_POST['lists'];
      $nletter=str_replace("rn","<br>",$nletter);
      //the block above formats the letter so it will send correctly.
      
	  
	  $getlist="SELECT * from volunteer WHERE event_id= '$event_id' "; //select e-mails in ABC order
      $getlist2=mysql_query($getlist) or die("Could not get list");
	  
	  while($getlist3=mysql_fetch_array($getlist2))
      {
         $headers = "From: $adminmail \r\n";   //unlock adminmail above and insert $adminmail for email address
         $headers.= "Content-Type: text/html; charset=ISO-8859-1 ";  //send HTML enabled mail
         $headers .= "MIME-Version: 1.0 ";     
         mail("$getlist3[email]","$subject","$nletter",$headers);
      }
      print "Your Message Has Been Sent.";
   }
}
else
{
   print "<form action='volunteer_send.php' method='post'>";
   print "Subject:<br>";
   print "<input type='text' name='subject' size='20'><br>";
   print "Message:<br>";
   print "<textarea name='nletter' cols='50' rows='6'></textarea><br>";
   print "<input type='submit' name='submit' value='submit'></form>";


}
?>
stoneman30
Forum Newbie
Posts: 4
Joined: Sun Mar 13, 2011 9:55 pm

Re: php mail form issue

Post by stoneman30 »

I assume that you are passing your event id as "id" in your URL to the initial form, as I don't see it on the [text]<form>[/text] tag in your else clause. You need your form tag to look like this:

Code: Select all

print "<form action='volunteer_send.php?id='".$_GET["id"]."' method='post'>";
WIthout that, your sql query is going to generate: SELECT * from volunteer WHERE event_id= ''....which will return you the whole volunteer database table.
Post Reply