Help with the mail() function

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
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Help with the mail() function

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post 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");

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post by anthony88guy »

where exactly am i missing a colon?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

:oops: ignore that bit ;)
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post by anthony88guy »

thanks alot it all works
Post Reply