PHP and mail forms

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux