Page 1 of 1

mail()

Posted: Tue Apr 20, 2004 7:52 am
by rkamun1
fellow warriors of the cathode tube,

I am kinda new to php and I am trying to use the send mail function to send mail. I am using data posted to the function from a form on the previous page. Now when I click send, I get the following errors

Notice: Undefined variable: subject in e:\inetpub\wwwroot\php\feedback.php on line 3

Notice: Undefined variable: message in e:\inetpub\wwwroot\php\feedback.php on line 3


I get the mail fine, but it has no subject and no body.....ok, so I guess I don't get it fine.

Is there something I am missing in my php.ini?

//feedback.html
<html><title>Email the Webmaster</title>
<form name="form" method="post" action="feedback.php">
<p>To: <input type="text" name="subject"></p>
<p>Message: <textarea name="message"></textarea></p>
<input type="submit" name="Submit" value="Submit">
</form></html>


//feedback.php
<html><title>Email Sent to Webmaster</title>
<?php
mail("emailaddy", $subject, $message) ;
?></html>

Posted: Tue Apr 20, 2004 7:55 am
by malcolmboston
try this, if this doesnt work its something wrong with your config

Code: Select all

$email = "youremail@me.com";
$subject = "TEST TEST TEST";
$message = "<body>Testing Mail Functionality</body>";
$headers  = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
// mail me
mail("$email", "$subject", "$message", "$headers");
this also supports HTML based e-mails

Posted: Tue Apr 20, 2004 7:57 am
by magicrobotmonkey
Do you have register_globals on or off in php.ini? I would guess off which means you need

Code: Select all

<html><title>Email Sent to Webmaster</title> 
<?php 
mail("emailaddy", $_POST['subject'], $_POST['message']) ; 
?></html>

Posted: Tue Apr 20, 2004 7:58 am
by malcolmboston
i should point out that the reason i do that is because i use this sort of thing in all my scripts

Code: Select all

$email = $_POST['email'];
$subject = $_POST['subject'];
just thought i'd point this out to avoid confusion

Posted: Tue Apr 20, 2004 8:53 am
by rkamun1
thanks guys, that definately helps, I had to either turn the global register on or explicitly post the data