Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Php... Help Please

  1. #1
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Php... Help Please

    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!

  2. #2
    Join Date
    Jan 2007
    Location
    Bournemouth, England
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You can find a prebuilt e-mail form easily.

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

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Code:
    <form action = "process.php" method="post">
    ...
    </form>

    process.php
    PHP Code:
    $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
    Last edited by boogyman; 05-18-2007 at 06:46 PM.

  4. #4
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks, here's the code

    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>

  5. #5
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I had to create it in two parts:

    Code:
        <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.
    ?>

  6. #6
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    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)

  7. #7
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

    Code:
     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

    Code:
    		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?

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •