Forum Moderators: coopster

Message Too Old, No Replies

Beginner Problem

PHP blank fields

         

generationXile

11:06 am on Oct 18, 2008 (gmt 0)

10+ Year Member



I just did my first php script. Its a simple email form on my site. Its just emailing blank fields, and sending the wrong email address to reply to, etc. If anyone can let me know what I did wrong, Id greatly appreciate it!
heres the code:

<?php

/*subject and email definitions */

$emailSubject = 'Live-Ops Signup Please';
$webMaster = 'webmaster@example.com';
$req = '1';

/*data to be sent */

$emailField = $_POST['email'];
$phoneField = $_POST['phone'];
$nameField = $_POST['name'];
$teamnameField = $_POST['teamname'];
$gameField = $_POST['game'];
$numberField = $_POST['number'];
$timeslotField = $_POST['timeslot'];

$body = <<<EOD
<br><hr><br>
Email: $email <br>
Contact Phone Number: $phone <br>
Name: $name <br>
Team Name: $teamname <br>
Number of Members on Team: $number <br>
Timeslot Requested: $timeslot <br>
Which Type of game they want: $game <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

/*results rendered as html*/

$theResults = <<<EOD
<html>
<head>
<title>Live-ops</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
body {
background-color: #000000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
}
body,td,th {
color: #FFFFFF;
}
-->
</style>
</head>

<div>
<div align="left">
<p>Thank you for using our web signup form. You will get a verification email as soon as we get your email and slot you in for the time that you requested. If we cannot do so, you will get an email letting you know the timeslot is not available. You may view the schedule with updated open slots below at the <a href="Schedule.htm">schedule</a> link.</p>
<p> You may also check our online calendar to see if your timeslot has been assigned to you. </p>
<p> See you at Live-ops!</p>
</div>
</div>
<div align="center">
<h5><font color="#CCCCCC"><a href="Videos.htm">VIDEOS</a> ¦ <a href="Contact.htm">CONTACT</a> ¦ <a href="Sponsor.htm">SPONSOR</a> ¦ <a href="Photos.htm">PHOTOS</a> ¦ <a href="calendar/calendar.htm">SCHEDULE</a></font></h5>
</div>
</body>
</html>
EOD;
echo "$theResults";


?>

[edited by: eelixduppy at 3:18 pm (utc) on Oct. 18, 2008]
[edit reason] exemplified [/edit]

RonPK

11:29 am on Oct 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$emailField = $_POST['email'];
[..]
Email: $email <br>

You haven't defined $email anywhere. Try using $emailField instead (the same goes for many other variables in the script).

Tip: use

error_reporting(E_ALL) [php.net];
at the top of your script while you're testing it. That will inform you about errors like this.

You may also wish to read up on email header injection [google.com], to prevent abuse of the script.

And welcome to WebmasterWorld!

generationXile

7:10 pm on Oct 18, 2008 (gmt 0)

10+ Year Member



Thanks for the Welcome!
I was looking into what you suggested, after finally getting some sleep (i was working on the site all night) and finally realized what I had done. When I redesigned my form I forgot to rename the text fields and for some reason they defaulted to "email2" "name2" etc. So ... DUH! The mistake was in my form, not my php. php cant take fields and report them to me if I defined the fields wrong.
Told ya I was a rookie. lol Thanks for the assistance though. I LOVE forums like this. Everyone coming together and helping each other. Thanks for the assistance and the forum everyone!

Pico_Train

3:32 pm on Oct 19, 2008 (gmt 0)

10+ Year Member



Before you keep trying to resend yourself the email to check it is working, do this:

above $success = mail($webMaster, $emailSubject, $body, $headers);

add this line

echo $body;

then comment out $success = mail($webMaster, $emailSubject, $body, $headers);

then "send" the email as is. It won't send the email but just spit out your email body so you can see if everything looks right before trying to send it proper.

Good luck!