Page 1 of 1

Help with the mail() function

Posted: Thu Jan 20, 2005 8:29 pm
by anthony88guy
I am creating a simple form where you just type your email address and a message and then it sends it to me. Its just a simple test for a bigger mailing list thing i will be making.

Here is my html code

Code: Select all

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#333333" text="#999966" link="#FFFF00" vlink="#999933" alink="#FFFF99">
<div align="center"> 
  <form action="mail.php" method="post" name="mail" id="mail">
    <p>Your Email:</p>
    <p> 
      <input name="from" type="text" id="from2" size="50">
    </p>
    <p>Message: </p>
    <p> 
      <textarea name="message" cols="43" rows="5" id="message"></textarea>
    </p>
    <p>
      <input type="submit" name="Submit" value="Send Mail">
    </p>
  </form>
<p>&nbsp;</p></div>
</body>
</html>
Thats my html and form, here is my php file code...

Code: Select all

<?

$to = "myemail@optonline.net";
$from = "email";
$subject = "From $from";
$message = "message";
mail($to, $subject , $message);
header("location:http://www.nokidding.websiteallies.com");

?>
I don't understand why when i try it out i get an email from nobody and the subject is : From email, and the body consist of message.

Thanks guys

Posted: Thu Jan 20, 2005 8:54 pm
by feyd
your php code asks php to store the strings "message" and "email" .. they have nothing to do with the form. $_POST['from'] and $_POST['message'] will be the information you're thinking should be there.

Posted: Thu Jan 20, 2005 9:19 pm
by anthony88guy
thank you, i can recieve an email now and it works, except that in the subject line i get: From $from

how do i go about fixing that?

thanks again

Code: Select all

<?

$to = "myemail@optonline.net";
$from = $_POST&#1111;'email'];
$subject = 'From $from';
$message = $_POST&#1111;'message'];
mail($to, $subject , $message);
header("location:http://www.nokidding.websiteallies.com");

?>

Posted: Thu Jan 20, 2005 9:24 pm
by feyd
single quotes vs. double quotes:

variables inside a singlequote string will not be parsed by php. Variables in a double quote string will.


note: you are missing a colon in the from string.

Posted: Fri Jan 21, 2005 12:10 pm
by anthony88guy
where exactly am i missing a colon?

Posted: Fri Jan 21, 2005 12:12 pm
by feyd
:oops: ignore that bit ;)

Posted: Fri Jan 21, 2005 2:06 pm
by anthony88guy
thanks alot it all works