PDA

View Full Version : $bbuser for email in php


xt07t
06-08-2004, 11:48 AM
I have created an email form for sending an email on my forum. I want to be able to use the logged in user name in the email. For example, here is a simple email form

<form action="email.php" method="post" name="emailform" target="_self">
Enter your email here:<br>
<input name="from" type="text" size="20" maxlength="20">
<hr>
Enter your message here:<br>
<textarea name="message" cols="30" rows="10"></textarea>
<input type="submit" value="submit">
</form>

The email.php file would be

<?php
$to = "test@test.com";
$from = $_POST['from'];
$subject = "This is a test email";
$message = $_POST['message'];
$headers = "From: $from\r\n";
$success = mail($to, $subject, $message, $headers);
if ($success)
echo "The email to $to from $from was successfully sent";
else
echo "An error occurred when sending the email to $to from $from";
?>


What I would like to be able to do here is put in the username that submited it. What would I need to put in the email.php file to do this? Thanks!!

xtort :confused:

Brian
06-08-2004, 11:50 AM
Why about adding a hidden input field with $bbuserinfo[username] as the value?

Our Sponsors
 

xt07t
06-08-2004, 11:55 AM
Why about adding a hidden input field with $bbuserinfo[username] as the value?

Would I need to put it inside <?php?>

ie.
<?php
<input name="username" type="hidden" value="$bbuserinfo[username]">
?>

xt07t
06-08-2004, 11:59 AM
The problem is that it just sends the text $bbuserinfo[username] and not the actual username. I have logged in and then linked to the url that is in the same server as the forum.

<input name="username" type="hidden" value="$bbuserinfo[username]">

Our Sponsors
 

Brian
06-08-2004, 12:15 PM
That form either needs to be inside one of your vB templates, or the file will need to require your global.php file in order to get the user's info.

xt07t
06-08-2004, 01:38 PM
So just use an include for the global.php then?

I can send the information through the url, but would prefer not to if I can help it.