PDA

View Full Version : Php... Help Please



kjgreeney
05-18-2007, 06:12 PM
Okay, I'm brand new to PHP and I'm doing pro-bono work for a friend, and I need help BADLY.

Everything works EXCEPT the submit button.

I just want this form to be emailed to an email address.

Please help me!

*NOTE: It said the text I entered was too long, so if you can help me, please pm me your email so I can email everything to you.*

Thanks!

killerchutney
05-18-2007, 06:21 PM
You can find a prebuilt e-mail form easily.

heres one I found, its free. http://www.maianscriptworld.co.uk/scripts_mail.html

boogyman
05-18-2007, 06:39 PM
<form action = "process.php" method="post">
...
</form>



process.php


$to = "email@url.com";
$subject = "subject of email";
$from = trim(htmlspecialchars($_POST['email']));
$message = "";

// Populates the Message Body to be sent
foreach($_POST as $key => $value) {
$message .= trim(htmlspecialchars($key . " - " . $value) . "<br />");
}


// Try To Send Email
if(!mail($to, $subject, $message, "From: $from")) {
// If failure of send email - print error
print "Cannot send email";
else {
print "Email Sent! Thanks";
}




// EDIT


*NOTE: It said the text I entered was too long, so if you can help me, please pm me your email so I can email everything to you.*
use the [c.ode][/c.ode] tags (without period) to wrap your text and you wont have to worry about text length

kjgreeney
05-18-2007, 07:13 PM
Thanks, here's the code




<?php # Script 3.13 - register.php

if (isset($_POST['submit'])) { // Handle the form.

$message = NULL; // Create an empty new variable.

// Check for a name.
if (strlen($_POST['CustomerName']) > 0) {
$name = TRUE;
} else {
$name = FALSE;
$message .= '<p>You forgot to enter your name!</p>';
}

// Check for an email address.
if (strlen($_POST['EmailAddress']) > 0) {
$email = TRUE;
} else {
$email = FALSE;
$message .= '<p>You forgot to enter your email address!</p>';
}

// Check for an address.
if (strlen($_POST['Address']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter your Address!</p>';
}

// Check for a City.
if (strlen($_POST['City']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter your City!</p>';
}

// Check for an State.
if (strlen($_POST['State']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter your State!</p>';
}

// Check for an ZipCode.
if (strlen($_POST['ZipCode']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter your Zip Code!</p>';
}

// Check for an Phone Number.
if (strlen($_POST['PhoneNumber']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter your Phone Number!</p>';
}

// Check for an Fax Number.
if (strlen($_POST['FaxNumber']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter your Fax Number!</p>';
}

// Check for an Website.
if (strlen($_POST['Website']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter your Website!</p>';
}

// Check for a First Design.
if (strlen($_POST['FirstDesign']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter your Design!</p>';
}

// Check for a First Quantity.
if (strlen($_POST['FirstQuantity']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter your Quantity!</p>';
}

// Check for a Phone Number.
if (strlen($_POST['FirstPhone']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter the Phone Number to appear on your cards!</p>';
}

// Check for a Stock Color.
if (strlen($_POST['FirstColor']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter the color of your cards! If Design 7 enter, White!</p>';
}

// Check for a Card Type.
if (strlen($_POST['CardType']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter the type of Card you are using!</p>';
}

// Check for a Card Number.
if (strlen($_POST['CardNumber']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter the Number on your Card!</p>';
}

// Check for a Card Name.
if (strlen($_POST['CardName']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter the Name that Appeard on your card!</p>';
}

// Check for a Expiration Date.
if (strlen($_POST['Expiration']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter the Expiration Date!</p>';
}

// Check for a Comments.
if (strlen($_POST['Comments']) > 0) {
$username = TRUE;
} else {
$username = FALSE;
$message .= '<p>You forgot to enter your comments! If you have none, please just place "none" in the box!</p>';
}

if ($CustomerName && $EmailAddress && $Address && $City && $State && $ZipCode && $PhoneNumber && $FaxNumber && $Website && $FirstDesign && $FirstQuantity && $FirstPhone && $FirstColor && $CardType && $CardNumber && $CardName && $Expiration && $Comments) { // If everything's okay.
// Register the user.

// Send an email.
$body = "Thank you for your order!\nYou will be receiving an email confirmation of your order very soon. The email you will receive this confirmation at is '{$_POST['EmailAddress']}'.\n\nSincerely,\nJennifer Greeney";
mail ($_POST['email'], 'Order Confirmation!', $body, 'From: jennifer.greeney@proforma.com');

header ('Location: thankyou.php');
exit();
} else {
$message .= '<p>Please try again.</p>';
}

}

// Set the page title and include the HTML header.
$page_title = 'Order Form';
include ('./header.inc');

// Print the error message if there is one.
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<div align="center">
<legend><font face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#000099">Enter
your information in the form below:</font></strong></font></legend>
</div>
<div align="center"><center>
<table width="544" cellspacing="6" background="fadedbackground.jpg" bgcolor="#F2F2F2">
<tr>
<td align="right" width="176"><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif"><small>*Your
name:</small></font></strong></td>
<td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29" name="CustomerName">
</font></td>
</tr>
<tr>
<td align="right" width="176"><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Your email address:</small></font></strong></td>
<td align="left" width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29"
name="EmailAddress">
</font></td>
</tr>
<tr align="middle">
<td align="right" width="176"><p><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Mailing/Ship To Address:</small></font></strong></p></td>
<td width="344" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29"
name="Address">
</font></td>
</tr>
<tr align="middle">
<td align="right" width="176"><p><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
City</small></font></strong></p></td>
<td width="344" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29"
name="City">
</font></td>
</tr>
<tr align="middle">
<td align="right" width="176"><p><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
State:</small></font></strong></p></td>
<td width="344" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29"
name="State">
</font></td>
</tr>
<tr align="middle">
<td align="right" width="176"><p><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Zip Code:</small></font></strong></p></td>
<td width="344" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29"
name="ZipCode">
</font></td>
</tr>
<tr align="middle">
<td align="right" width="176"><p><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Phone Number:</small></font></strong></p></td>
<td width="344" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29"
name="PhoneNumber">
</font></td>
</tr>
<tr align="middle">
<td align="right" width="176"><p><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Fax Number:</small></font></strong></p></td>
<td width="344" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29"
name="FaxNumber">
</font></td>
</tr>
<tr align="middle">
<td align="right" width="176"><p><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Website:</small></font></strong></p></td>
<td width="344" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29"
name="Website">
</font></td>
</tr>

kjgreeney
05-18-2007, 07:14 PM
I had to create it in two parts:




<tr align="middle">
<td align="right" width="176"><p>&nbsp;</p></td>
<td width="344" align="left"><strong><font color="#FF0000" size="3" face="Verdana, Arial, Helvetica, sans-serif">ORDER
YOUR CARDS BELOW</font></strong></td>
</tr>
<tr>
<td align="right" width="176"><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Design of Card:</small></font></strong></td>
<td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29" name="FirstDesign">
<strong><font color="#0000CC" size="1">(For Reference Click <a href="www.scottandjudith.com/carddesigns.html" target="_blank">Here</a>)</font></strong></font></td>
</tr>
<tr>
<td align="right" width="176"><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Quantity:</small></font></strong></td>
<td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29" name="FirstQuantity">
</font></td>
</tr>
<tr>
<td align="right" width="176"><p><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Phone Number </small> <br>
<small><em>to Appear on Card:</em></small> </font></strong></td>
<td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29" name="FirstPhone">
</font></td>
</tr>
<tr>
<td align="right" width="176"><p><strong><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Color of Card<em>:</em></small> </font></strong></td>
<td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29" name="FirstColor">
</font></td>
</tr>
<tr>
<td align="right" width="176"><p align="center"><font color="#0000FF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Important
information on order more than one design:</strong></font></td>
<td width="344"><p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><em><font color="#0000FF">*If
additional cards are desired enter them in the comments section
before you submit your order. Enter the Design Number, Quantity,
Card Color and Phone Number. </font></em></font></p>
<p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><em><font color="#0000FF">A
Order Confirmation will be sent to the email address you've provided
above, please make sure it is valid. </font></em></font></p>
<p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><em><font color="#0000FF">Thank
you.</font></em></font></p></td>
</tr>
<tr>
<td align="right" width="176"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
<td width="344"><font color="#FF0000" size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong>PAYMENT
INFORMATION:</strong></font></td>
</tr>
<tr>
<td align="right" width="176"><font color="#000066"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Card Type:</small></font></strong></font></td>
<td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29" name="CardType">
<strong><font color="#0000FF" size="1">(abbreviations accepted)</font></strong></font></td>
</tr>
<tr>
<td align="right" width="176"><font color="#000066"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Card Number:</small></font></strong></font></td>
<td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29" name="CardNumber">
</font></td>
</tr>
<tr>
<td align="right" width="176"><font color="#000066"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Name on Card:</small></font></strong></font></td>
<td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29" name="CardName">
</font></td>
</tr>
<tr>
<td align="right" width="176"><font color="#000066"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Expiration Date:</small></font></strong></font></td>
<td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input class="inputc" size="29" name="Expiration">
<strong><font size="1">(Format: 01/2008)</font></strong></font></td>
</tr>
<tr>
<td align="right" width="176"><font color="#000066">&nbsp;</font></td>
<td width="344"><font color="#FF0000" size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong>COMMENTS
OR ADDITIONAL CARDS:</strong></font></td>
</tr>
<tr>
<td align="right" width="176"><font color="#000066"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;
</font> </strong>
<p><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">*<small>
Your comments:</small></font></strong></font></td>
<td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<textarea style="FONT-SIZE: 10pt" name="Comments" rows="7" cols="40"></textarea>
</font></td>
</tr>
<tr>
<td width="176"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
<td width="344"><p> <font color="#0000FF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Y</strong><small><small><strong>ou
must fill in the fields marked with a *</strong></small></small></font></p></td>
</tr>
</table>
</center></div>
</fieldset>

<div align="center"><input type="submit" name="submit" value="Submit Information" /></div>

</form><!-- End of Form -->

<?php
include ('./footer.inc'); // Include the HTML footer.
?>

blm126
05-18-2007, 09:04 PM
Um,at a quick glance it looks like you copy and pasted the if/else statement block, but forgot to change $username to the correct variable.
So, when the code got to the final if, the undefined variables evaluated to false. You can prevent mistakes like this setting your error reporting level to E_ALL(check the manual for details)

kjgreeney
05-24-2007, 02:38 AM
I cannot believe I over looked that.

I went back and changed everything to the correct statements and now it's throwing this


Warning: mail() [function.mail]: SMTP server response: 501 unacceptable mail address in D:\Inetpub\wwwroot\nt04\jamestranstech.com\register1.php on line 156


mail ($_POST['EmailAddress'], 'Order Confirmation!', $body, 'From: jennifer.greeney@sbcglobal.net');

Warning: Cannot modify header information - headers already sent by (output started at D:\Inetpub\wwwroot\nt04\jamestranstech.com\register1.php:156) in D:\Inetpub\wwwroot\nt04\jamestranstech.com\register1.php on line 158


header ('Location: thankyou.php');
exit();
} else {
$message .= '<p>Please try again.</p>';
}

}

// Set the page title and include the HTML header.
$page_title = 'Order Form';
include ('./header.inc');

// Print the error message if there is one.
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}


Any suggestions?

djr33
05-24-2007, 02:57 AM
Headers are sent out before any html or other text on the page.

All headers must be sent at the top of your script before ANYTHING else is output. Any echo commands or any html blocks outside of the PHP must be after that and only after that.

kjgreeney
05-24-2007, 03:09 AM
I thought so in reading about PHP but I cannot figure out where exactly to put it. Again I'm totally new to PHP.

Any suggestions on where I should place the header?

Any help is appreciated.

djr33
05-24-2007, 03:21 AM
Before everything else that might output any html, etc. Simple as that. You may need to reorder some stuff or do something complex, but simply put, you MUST have it before any output.

As for the mail issue, the answer must be that $_POST['EmailAddress'] is not set correctly. Use a line of "echo $_POST['EmailAddress'];", to check if that was set. (Remove this for the final script, obviously.)

kjgreeney
05-25-2007, 01:11 AM
When I tried the echo statement it threw this error and wouldn't even open the page,



Parse error: parse error, unexpected T_ECHO in D:\Inetpub\wwwroot\nt04\jamestranstech.com\register1.php on line 156


Also, if you will take a second and help scan over the beginning of the code, isn't the header before anything that outputs html?

Like I said, I'm new, so thanks for bearing with me.

kjgreeney
05-25-2007, 01:28 AM
The book I'm ready said to move the entire Isset () conditional to the very top of the page above the if (isset($_POST['submit'])) and I did that and now it only directs me to thankyou.php when I am at the page.

To see what I'm talking about go to www.jamestranstech.com/register1.php

:(

kjgreeney
06-05-2007, 02:21 AM
can anyone help me??

alexjewell
06-05-2007, 02:18 PM
Hmm, djr33 is right about the headers. What's puzzling me is I don't see anything actually being echoed before that?

And...that isn't good. The solution for the redirection at the right time is to move the actual script to a different page and have the form submit to that different page. Make sense?

The other thing I was wondering, even though a bit off topic, is how secure you're making this? Any encryption/secure server? People aren't going to want to send their credit card info online if there's no security, and for good reason.

djr33
06-05-2007, 05:44 PM
Looks like there isn't actually anything echoed first. I was looking at the small bit of code you posted last, which seemed to imply there may have been html before that. Looking back over all of it, I don't see any conflicts there.

However, this is still worth considering in that you have a confirmation message "...confirmation email sent to [email]." but it doesn't ever get displayed if you just redirect with a location header after that.


The unexpected T_ECHO is an error basically meaning that something in the syntax is off. It could be a missing semicolon (likely), open brackets/parentheses, two lines run together, etc.
Take a close look at that line and the one before it and the one after it. If you can't find the error, post those three lines. (Very likely it's right around the problem area, so we probably don't need the whole script.)

suedree
06-06-2007, 03:35 AM
Cannot modify header information - headers already sent by (output started at D:\Inetpub\wwwroot\nt04\jamestranstech.com\register1.php:156) in D:\Inetpub\wwwroot\nt04\jamestranstech.com\register1.php on line 158


I dunno if it work or not but I always got that error, sometimes it's just that your page after submitted form have spaces... make sure there's no space in between php code and html... it worth it to try...

<?php echo "sample php code";?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">