[PHP-DB] How to test PHP form for proper input

2007-08-03 Thread Phil Matt
I've got a mail form that automatically pulls in the addressee from a MySQL db, 
and lets the sender
fill in his/her own info before sending. I figured out how to set up tests for 
legal input in the
different fields, but I don't know how to incorporate the test results into my 
form submission code.
(Sorry for the dumb question, but I'm not an experienced PHP coder...)

Here the basic stuff:

//SENDS MAIL
?
if ($submit){
mail($recipient, $subject, $message, From:\$from_name\$from_email\r\n .
Reply-to: $from_email\r\n .   
X-Mailer: PHP/ . phpversion());
echo h1Your message has been sent!/h1;}
?
//FORM USED

form name=mymail id=talign3 method=post action=? $_SERVER['PHP_SELF']; 
?
table class=bg summary=Form for sending email cellspacing=0
tr rowspan=2th colspan=3Send e-mail to: ? $recip=$_GET['recip']; echo 
$recip; ?/th/tr
tr
  td width=23%label for=your nameYour Name/label/td
  td width=77%input name=from_name type=text id=from_name 
value=?=$from_name?
size=45/td
/tr
tr
  td nowraplabel for=email addressYour Email Address/label/td
  td width=70%input name=from_email type=text id=from_email 
value=?=$from_email?
size=45/td
/tr
tr
  tdlabel for=subjectSubject/label/td
  tdinput name=subject type=text id=subject value=?=$subject? 
size=55/td
/tr
tr
td style=vertical-align:topMessage/td
  tdtextarea name=message cols=45 rows=15 
id=message?=$message?/textarea/td
/tr
tr

  tddiv align=right
  input name=userid type=hidden id=userid value=?$to_name? /
  input name=cmd type=hidden id=cmd value=validate_form
  input type=submit name=submit value=send mail
/div/td
/tr
  /table/form

//TESTING CODE
?
  $pattern = '/[EMAIL PROTECTED]/';
  extract($_POST);
  /*validate*/
  function check_from($from_name)
  {
  if(!preg_match(/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\]+$/s,$from_name))
  return TRUE;
  else
  return FALSE;
  }
  function check_email($from_email)
  {
  if (!preg_match($pattern,$from_email))
  return TRUE;
  else
  return FALSE;
  }
  function check_subject($subject)
  {
  if(!preg_match(/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\]+$/s,$from_name))
  return TRUE;
  else
  return FALSE;
  }
  function check_message($message)
  {
  if(!preg_match(/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\]+$/s,$message))
  return TRUE;
  else
  return FALSE;
  }
 /*test fails*/
 $error=0; // check up variable
 /*start*/
 if(!check_from($from_name))
 {
 echo You haven't entered your name in the Name box!;
 $error++; // $error=$error+1;
 }
 if(!check_email($from_email))
 {
 echo You haven't entered a valid email address in the email box!;
 $error++;
 if(!check_subject($subject))
 {
 echo You haven't entered your name in the Name box!;
 $error++;
 if(!check_message($message))
 {
 echo You haven't entered anything in the Message box!;
 $error++;
 }
 if($error==0)
 {echo
 Thank you for your email. You should receive a reply shortly from the staff 
person you contacted;
 } else
 {
 echoNumber of errors: $error;
 }
 ?

TIA for your help!

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Mailto and PHP

2007-06-14 Thread Phil Matt


De-lurking here. I am trying to modify a mailing script that I originally wrote to use a small form 
to send mail to different people from a MySQL database. I would like to modify it so that instead of 
using a form, the user's regular default email program opens on activating the link. I can't quite 
figure out how to pass the right parameters. Here's the relevant part of the existing script:


echo'tr class=shader'.$line.'a
td'.$myrow[0].'/tdtd'.$myrow[1].'/tdtd'.$myrow[2].'/td
td'. $myrow[4].'/td
	tda href=NEWmail.php?id='.urlencode($myrow[6]).'recip='.urlencode($myrow[0]. 
.$myrow[1].,br / .$myrow[2]).'img src=somegraphic.gif class=imglink width=20 
height=17 alt=Click to send mail to this person //a/td/tr';



I want to change the link to mailto: instead of the other PHP page, and then pass the recipient 
email address and recipient name and title, which are already there from the MySQL connection.


I've looked around for the right syntax, but it just escapes me. I have the Welling  Thompson book, 
but it only mentions that this can be done, without a clue as to how to do it. Pardon my ignorance, 
but this is not my area of expertise.


TIA for your collective wisdom!


--- P. Matt

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] PHP and mail forms

2004-01-30 Thread Phil Matt
Ricardo Lopes wrote: 

 There are several ways to do this. 
 Some people like the approach: 
  
 if ($submit) { send_email(); } 
  
 or you can put a hidden field in your form, like op: 
  
 input name=op type=hidden id=op value=send / 
  
 and use: 
  
 if (isset($HTTP_GET_VARS['op'])  ($HTTP_GET_VARS['op'] == 'send')) 
 { 
 send_email(); 
 } 

Thanks again, Ricardo. I now have the form communicating with the server. 

I think that I might have an error in my script: 

Where I join together the value of the passed variable ($myrow[3]) and the string  
containing the domain ( $string=@somedomain.com)  I used: 

 $to_name=$myrow[3]$string 

If the passed variable's value is, for instance, smith, then does my $to_name 
become: 

[EMAIL PROTECTED] 

On hitting the submit button, I see the server being called and data being sent, but  
nothing is being received. I'm just wondering if I've appended those two things 
correctly. 

TIA for your continued assistance. 

Cheers --- Phil 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] PHP and mail forms

2004-01-29 Thread Phil Matt
Hello to all.

I am trying to write a simple (at least I thought it was simple...) Contact Us form 
that 
sends an email when it is submitted.

The $to_name variable was passed from a previous page. I am sure that the variable 
was passed, as I can echo it and it is being passed correctly - thanks to this list!

The problem I am having is this: I cannot quite figure out how an html form handles 
this 
mail function when the to field is filled with an existing variable.

This is what I've got: (I removed all of the table formatting to make it clearer here)

form name=mailer method=post action=? $_SERVER['PHP_SELF']; ?
input name=from_name type=text id=from_name value=?=$from_name?
input name=from_email type=text id=from_email value=?=$from_email?
input name=subject type=text id=subject value=?=$subject? size=60
textarea name=message cols=55 rows=15 
id=message?=$message?/textarea

input name=userid type=hidden id=userid value=?$to_name? /
  input type=submit name=Submit value=mail

So, I think that this sets up the form for processing, AFAIK.

Then, I added the stuff that pulls the email address associated with the id in 
$to_name 
from the MySQL database, and adds the string for the proper domain. I've left out the 
connection stuff for clarity:

$id=$_GET['id'];
$string=@somedomain.com;
$result= mysql_query(SELECT * FROM mydatabase WHERE ID=$id,$db);
while ($myrow = mysql_fetch_row($result)){
$to_name=$myrow[3]$string; } ?

I know that the thing that actually sends mail looks like this:

mail($to_name, $from_name, $subject, $message, From: $from_email\nX-Mailer: PHP/ 
.. phpversion());   

But how do I get this all to happen when the user hits the submit button? Where does 
that mail function (is it a function?)  go? I have read a lot of stuff on the various 
PHP lists 
and sources, but I just cannot figure out this piece of the puzzle.

TIA for your suggestions, and for your patience with my lack of knowledge here.

-- Phil Matt

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Problem with passing variables

2004-01-27 Thread Phil Matt
Hello to all.

I am a relative newcomer to PHP. I am trying to pass the value of a variable from a 
MySQL database from one PHP page to another PHP page. On the first page, I've made 
the connection to the database, and the query works just fine, displaying the correct 
values from the $myrow fields.

This is the code to that point:

? 
$db = mysql_connect(ip address here,user here,password here) or die (Unable to 
connect to SQL server);
mysql_select_db(databasename,$db);
;
$result= mysql_query(SELECT * FROM databasename WHERE ID20,$db);
echo'table
thtrtdName/tdtdTitle/tdtdPhone/tdtdE-mail/td/tr/th';
while ($myrow = mysql_fetch_row($result)){
echo'tr
td'. $myrow[0].'/td
td'. $myrow[1].'/td
td'. $myrow[2].'/td

This works just fine. Then I try to pass the variable $myrow[0] to a second page, 
where 
the value of the variable (a string that contains a name) is supposed to appear. 
Here's 
the line of code:

tda href=email.php?recip=$myrow[0]img src=graphics/mail.gif class=imglink 
alt=Click to send mail to this person //a/td/tr';


The page receiving this variable, email.php, uses this to retrieve the value of 
$myrow[0]:

Send e-mail to ?php $recip=$_GET['recip']; echo $recip; ?


However, all this manages to do is to print out this:

Send e-mail to $myrow[0]

Instead of the VALUE contained in the variable!

What am I doing wrong?

TIA --- Phil Matt






-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Problem with passing variables

2004-01-27 Thread Phil Matt
On 27 Jan 2004 at 15:56, Ricardo Lopes wrote:

 If you have something like this:
 
 echo 'tda href=email.php?recip=$myrow[0]img src=graphics/mail.gif
 class=imglink alt=Click to send mail to this person //a/td/tr';
 
 It wont work. Use instead:
 
 echo 'tda href=email.php?recip='.$myrow[0].'img
 src=graphics/mail.gif class=imglink alt=Click to send mail to this
 person //a/td/tr';
 
 Notice the '. before the $myrow[0] and the .' after, any doubt see the
 documentation about operators.
 
 This is caused because the ' doesnt parse variables to values like the 
 does.
 

Ricardo - That's it!  I did read a lot of PHP docs and mailing list posts before I 
posted my 
question to this list, but never stumbled (and that's the word, I'm afraid!) on the 
syntax 
explanation that would untangle this for me.

If I want to pass additional variables for processing on the second page, I'm assuming 
that the syntax would be (where $foo is another variable)

a href=email.php?foo='.$myrow[3].'?recip='.$myrow[0].' 

Thanks again for restoring my sanity!

Cheers --- Phil Matt