For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > May 2007 > email basics









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author email basics
Kevin Raleigh

2007-05-26, 6:58 pm

Using this form

<form method="post" action="do_sendfeedback.php">
Your Name:   <input type = "text" name="sender_name" size=20><br>
Your email address: <input type="text" name="sender_email" size=30><br>

Did you like this site?<br>
<input type = "radio" name="like_site" value="yes" checked> Yes<br>
<input type = "radio" name="like_site" value="no"> No<br>
<br>
Additional Message: <br>
<textarea name="message" cols=60 rows=10>Your message here!</textarea><br>

<input type="submit" value="Send this form">
</form>

And this collection page:

<?php_track_vars?>

<?php

$msg = "Sender's Full Name: \t$sender_name\n";
$msg.= "Sender's E-Mail:\t$sender_email\n";
$msg.= "Did You Like the Site?\t$like_site\n";
$msg.= "Additional Message:\t$message\n\n";

$mailheaders = "From: My Web Site\n";
$mailheaders.= "Reply-To: $sender_email\n\n";

mail("kraleigh@sbcglobal.net", "Feedback Form", $msg, $mailheaders);

echo "<H1 align=center>Thank You, $sender_name</H1>";
echo"<P align=\"center\">We appreciate your feed back.</P>";
?>

I have errors indicating that my variables don't exist or something like
that

PHP Notice: Undefined variable: sender_name in
C:\Inetpub\wwwroot\phpBasics4.0\do_sendfeedback.php on line 4

PHP Notice: Undefined variable: sender_email in
C:\Inetpub\wwwroot\phpBasics4.0\do_sendfeedback.php on line 5

PHP Notice: Undefined variable: like_site in
C:\Inetpub\wwwroot\phpBasics4.0\do_sendfeedback.php on line 6

PHP Notice: Undefined variable: message in
C:\Inetpub\wwwroot\phpBasics4.0\do_sendfeedback.php on line 7

PHP Notice: Undefined variable: sender_email in
C:\Inetpub\wwwroot\phpBasics4.0\do_sendfeedback.php on line 10

PHP Notice: Undefined variable: sender_name in
C:\Inetpub\wwwroot\phpBasics4.0\do_sendfeedback.php on line 14

can you advise

Kevin


Geoff Berrow

2007-05-27, 7:58 am

Message-ID: < LNWdnUYdJMmLVcXbnZ2dnUVZ_rOqnZ2d@giganew
s.com> from Kevin
Raleigh contained the following:

>can you advise


Newer versions of PHP have register globals disabled by default as a
security measure.

You'll find the variables in the $_POST array so you need something
like

$msg = "Sender's Full Name: \t".$_POST[' sender_name']."\n";
$msg.= "Sender's E-Mail:\t".$_POST[' sender_name']."\n";

and so on.

Note the use of the dot as the concatenation operator. Alternatively
you could do

$msg = "Sender's Full Name: \t$_POST[ sender_name]\n";
$msg.= "Sender's E-Mail:\t$_POST[ sender_name]\n";

and so on.

Some people prefer to simply extract the variables first
$sender_name= $_POST[ 'sender_name'];
$sender_email=$_POST[ 'sender_email'];
etc..
Put this at the beginning and your existing code will work just fine.

--
Geoff Berrow 0110001001101100010000000110
0011011010110110010001101111011001110010
11
1001100011011011110010111001110101011010
11
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com