mail()

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
rkamun1
Forum Newbie
Posts: 4
Joined: Mon Apr 19, 2004 9:54 pm

mail()

Post 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>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post 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>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
rkamun1
Forum Newbie
Posts: 4
Joined: Mon Apr 19, 2004 9:54 pm

Post by rkamun1 »

thanks guys, that definately helps, I had to either turn the global register on or explicitly post the data
Post Reply