Defining Variables

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
masson
Forum Newbie
Posts: 4
Joined: Wed Jan 31, 2007 8:53 am

Defining Variables

Post by masson »

I am just beginning with programming and heard PHP would be a good starting point. Is there a forum for newbies? I have several questions that would be trivial for experienced developers and I do not want to clutter the forums.

One example: I created a form that collects user information including some expenditures (form.php). Upon submission, this information is posted for review and the expenditures are totaled (formReview.php). This all works fine. However I do not know how to pass the email address collected in form.php to the mail form, mailform.php.

In form.php I collect the email address with:

Code: Select all

<input type="text" name="toEmail">
then display the address for conformation in formReview.php with:

Code: Select all

<?php echo $_POST["toEmail"]; ?>
I have the following in mailform.php

Code: Select all

<?php

$to = "";                             <- would like to insert "toEmail" from HTML input name value
$subject = "Reimbursement";           <- set value, standard subject line
$message = "";                        <- would like to send entire formatted form (no idea how to capture this)
$from = "";                           <- would like to insert "fromEmail" from HTML input name value
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Thank you, Mail Sent.";

?>
Is it possible to insert the $_POST["toEmail"] into a variable?

Thanks,
Jack
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Try it.

I suggest reading through most of the manual, as well. You should already know the answer to this question, really.
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Post by louie35 »

Code: Select all

// set empty variable
$toEmail = "";

#first you need to check them out if there are any values posted
#then you could set the variable like this
if(isset($_POST["toEmail"]) && ($_POST["toEmail"] != NULL)){
    $toEmail = $_POST["toEmail"];
}


<?php 

$to = "your_email here";                            // <- would like to insert "toEmail" from HTML input name value 
$subject = "Reimbursement";         //  <- set value, standard subject line 
$message = "the message from the textarea";                        //<- would like to send entire formatted form (no idea how to capture this) 
$from = $toEmail ; // here we adding the new variable create                  // <- would like to insert "fromEmail" from HTML input name value 
$headers = "From: $from"; 
mail($to,$subject,$message,$headers); 
echo "Thank you, Mail Sent."; 

?>
masson
Forum Newbie
Posts: 4
Joined: Wed Jan 31, 2007 8:53 am

Thanks, its working

Post by masson »

thank you, I added the empty variable and also added a hidden import to set it. I noticed there is a peer review forum "Coding Critique," when I am done I think I'll submit it. I am sure it will be beneficial for me. Thanks again
Post Reply