Jump to content

[SOLVED] Contact Form - How do I set the "from"


Irresistable

Recommended Posts

I have this contact form. - What it's suppose to do, is have two fields, message and subject. The user has to be logged in to submit the form, and with the session, it gets the users "username" (So admin can identify the user) and.. it gets the users email from the database. It does get the email address, as i checked it with the body, and it comes up correct.

 

The code below, when I recieve the email it comes up as..:

  Time                            From                                    Subject              Size

13:59:37  To: [email protected]  Reporting A Problem  655

 

It should display the from address.. which in my case.. when I submit the form, it is admin. It shouldn't contain the "To:" though.

 

Here is my PHP code

 

<?php session_start(); 

include("config.php");
if(isset($_POST['submit'])) {

$username = ucwords($_SESSION['s_username']);
$query = mysql_query("SELECT Email FROM Users WHERE Username = '$username' LIMIT 1") or die(mysql_error());

$user = mysql_fetch_array($query);

$to = "[email protected]";
$subject = $_POST['subject'];
$name = $username;
$email = $user['Email'];
$message = $_POST['message'];

$body = "$message\n\n $name";

echo "Data has been submitted to $to!";

mail($to, $subject, $body, "From: $name <$email>\r\n");
} else {
echo "<strong>Error, something has gone wrong, please try again later.</strong>";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.