Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    3
    Thanked 0 Times in 0 Posts

    PHP Form Not Working

    All,

    I'm having trouble with a contact form on one of my websites. I've been using the same form on a couple of my websites with no problems but it's not working on a website I'm building at the moment.

    It's a form I made on the phpFormGenerator website and like I just mentioned it does work OK on my other websites. The contact form is at Wayne Barry's Tree Services - About Us And Contact Page

    The HTML for the contact page and form is as follows:
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Wayne Barry's Tree Services - About Us And Contact Page</title>
    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
    <meta name="description" content="Wayne Barry's Tree Services is a family owned and run business servicing 
    Geelong, Bellarine Peninsula, the Surf Coast and all surrounding areas. Contact us today 
    to take care of all your tree felling &amp; tree maintenance, garden mulch and tower hire needs." />
    <meta name="keywords" content="contact" />
    <meta name="robots" content="index, follow" />
    	
    																				<link rel="stylesheet" type="text/css" href="http://www.treecycle.com.au/dev/css/styles.css" media="Screen" />
    																				<link rel="stylesheet" type="text/css" href="http://www.treecycle.com.au/dev/css/mobile.css" media="handheld" />
    																				<link media="only screen and (max-device-width: 480px)" href="http://www.treecycle.com.au/dev/css/mobile.css" type="text/css" rel="stylesheet" />
    	
    </head>
    <body>
    
    <div id="wrapper">
    
    	<a href="tel://+61418522351"><div id="mobile_header"></div></a>
    	<div id="phoneBlock"></div>
    	<div id="header"></div>
    	
    	<div id="nav">
    			 					<table class="tableNav"><tr>
    								<td class="tableNav"><a href="/dev/index.html">Home</a></td>
    								<td><a href="/dev/tree_lopping.html">Tree Services</a></td>
    								<td><a href="/dev/stump_grinding.html">Stump Grinding</a></td>
    								<td><a href="/dev/garden_mulch.html">Tree Mulch</a></td>
    								<td><a href="/dev/tower_hire.html">Tower Hire</a></td>
    								<td><a href="/dev/formgenerator/forms/contact.html">About/Contact Us</a></td>
    								</tr>
    								</table>
    	</div>
    	
    				<div id="content-2">
    						 <div id="top_border"></div>
    						 		 <div id="content-2-1" style="min-height: 600px;">
    								 			<img src="http://www.treecycle.com.au/dev/images/mulch_truck.jpg" class="image_right" alt="Wayne Barry's Tree Services">
    										<span class="blackheading">Wayne Barry's Tree Services - About Us</span>
    			<p>Wayne Barry's Tree Services is a family owned and operated tree felling business located 
    			at Batesford, Geelong. We have over 28 years experience in tree felling, trimming and 
    			tree maintenance. Our qualified arborists have Red Card accreditation and we take great 
    			pride in the quality of our work. We aim to do all our work to the highest safety standards 
    			and with the least impact on the environment.
    			<br /><br />
    			We have both government and commercial customers as well as servicing suburban and rural 
    			clients.
    			<br /><br />
    			We cover the Greater Geelong, Bellarine Peninsula, Surf Coast, and all surrounding 
    			areas. No job is too big or too small so contact us for all your tree removal, tower hire and garden 
    			mulch needs!
    			</p>
    
    
    <div id="formLH">
    			
    <form enctype='multipart/form-data' action='process.php' method='post'>
    									
    									 <table class="tableContact">
    									 <tr>
    									 <td><label for="user">Name:</label></td>
    									 <td><input type="text" name="Name" value="" /><br></td></tr>
    									 
    									 <tr>
    									 <td><label for="emailaddress">Email Address:</label></td>
    									 <td><input type="text" name="Emailaddress" value="" /><br></td></tr>
    									 
    									 <tr>
    									 <td><label for="enquiry">Enquiry:</label></td>
    									 <td><textarea name="Enquiry"></textarea><br></td></tr>
    									 	
    									 <tr>	
    									 <td></td><td><input type="submit" name="submitbutton" id="submitbutton" value="Submit" /></td></tr>
    									 <tr><td></td><td><input type=reset value='Clear Form' id="clearbutton" /></td></tr>
    									 </table>
    
    									 </form>
    									 
    									 </div>
    
    <div id="contactRH">
    									 
    									 <span class="blackheading">Wayne Barry's Tree Services - Contact Us</span>
    									 <p><b>Wayne Barry's Tree Services</b><br />
    									 335 Ballarat Rd, Batesford,<br />
    									 Geelong, 3221<br />
    									 PO Box 5457, North Geelong, 3215
    									 <br /><br />
    									 Phone/Fax - <b>(03) 5276 1669</b><br />
    									 Wayne - <b>0418 522 351</b><br />
    									 David - <b>0407 522 900</b><br />
    									 Email - <a href="mailto:enquiries@treecycle.com.au?subject=Website Enquiry" style="color: blue;">enquiries@treecycle.com.au</a>
    									 </p>
    
    								</div>
    								
    								</div>
    								
    						<div id="bottom_border"></div>
    				</div>
    	
    	<div id="footer">
    			 <table class="tableFooter" summary="Footer">
    			 <tr>
    			 <td><a href="/dev/index.html">Home</a></td>
    			 <td>|</td>
    
    			 <td><a href="/dev/tree_lopping.html">Tree Services</a></td>
    			 <td>|</td>
    
    			 <td><a href="/dev/stump_grinding.html">Stump Grinding</a></td>
    			 <td>|</td>
    
    			 <td><a href="/dev/garden_mulch.html">Tree Mulch</a></td>
    			 <td>|</td>
    
    			 <td><a href="/dev/tower_hire.html">Tower Hire</a></td>
    			 <td>|</td>
    			 
    			 <td><a href="/dev/formgenerator/forms/contact.html">About/Contact Us</a></td>
    			 
    			 </tr>
    			 </table>
    			 
    			 <table class="tableTrade">
    			 <tr>
    			 <td>Tree Cycle PTY LTD trading as Wayne Barry's Tree Services</td>
    			 </tr>
    			 </table>
    			 
    	 </div>
    	
    </div>
    
    </body>
    </html>
    Once the form is submitted it calls the process.php page, it's code is:
    Code:
    <?php
    include("global.inc.php");
    $errors=0;
    $error="The following errors occured while processing your form input.<ul>";
    pt_register('POST','Name');
    pt_register('POST','Emailaddress');
    pt_register('POST','Enquiry');
    $Enquiry=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Enquiry);if($Name=="" || $Emailaddress=="" ){
    $errors=1;
    $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
    }
    if($errors==1) echo $error;
    else{
    $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
    $message="Name: ".$Name."
    "Email address: ".$Emailaddress."
    "Enquiry: ".$Enquiry."
    ";
    $message = stripslashes($message);
    mail("andrew@frcclothing.com.au","Form Submitted at your website",$message,"From: phpFormGenerator");
    
    header("Refresh: 0;url=http://www.treecycle.com.au/dev/index.html");
    ?><?php
    }
    ?>
    When I hit Submit the browser just seems to stall at the process.php page when it should refresh through to the index page. It also doesn't seem to be sending the form data through to my email account either.

    The exact same form works on my other site, that site is on the same host, the folder structure is exactly the same as well so I have no idea why it won't work in this instance.

    Any help is appreciated.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,128
    Thanks
    80
    Thanked 4,556 Times in 4,520 Posts
    The enctype='multipart/form-data' is not normally used except with <form>s that have <input type="file"> fields.

    I'm 90% sure you need to remove that.

    From section 17.3 on this page: Forms in HTML documents
    enctype = content-type [CI]
    This attribute specifies the content type used to submit the form to the server (when the value of method is "post"). The default value for this attribute is "application/x-www-form-urlencoded". The value "multipart/form-data" should be used in combination with the INPUT element, type="file".
    Last edited by Old Pedant; 08-09-2014 at 03:48 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Old Pedant, thanks a lot for your reply.

    Tried removing that piece of code but it didn't seem to make a difference, the process still stalls at the process.php page.

    Very frustrating given that the exact same form works fine on my other site.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,128
    Thanks
    80
    Thanked 4,556 Times in 4,520 Posts
    Do you even *GET* to the process.php page?

    I would temporarily rename that file to "process_backup.php" and then create a new "process.php" page that does nothing but
    Code:
    <html>
    <body>
    HTML content<hr/>
    <?php
    echo "PHP content<hr/>";
    ?>
    </body>
    </html>
    See if you get to the page. See if you see the HTML content. Check if you see the PHP generated content.

    Hmmm???

    If you get the PHP content, then time to start PHP debugging of the original code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    chocko638 (08-16-2014)

  • #5
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I was getting to the process.php page, or at least the url would change to it in the address bar but the browser would just show a blank page.

    OK, took your advice and put your code into a new process.php page and uploaded it. It worked, I got the page showing the line of HTML and the line of generated PHP.

    I have this same form working on another site so I downloaded a copy of the process page from there and just changed the mail address to my email and also changed the refresh url to the index page of my development site.

    It has worked in so far as when I submit the form it moves through the process page and then to the index page, I've checked and double checked that my original process code was correct (or at least the same as what I'm using on my other site) but regardless after using a fresh copy it now seems to be working. That was about 10 minutes ago and I'm yet to get the form content delivered to my email though so I'm going to give that a while longer and see.

    Thanks very much for your help.

  • #6
    New to the CF scene
    Join Date
    Aug 2014
    Location
    Indaia, Dlhi
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Simple PHP form. These instructions will enable you to create a simple form, once it is submitted it will reload the same page with the form contents in the place of the form.

    > Create the page for your form. We'll call it 'form.php'.
    <html>
    <head>
    <title>Test Form</title>
    </head>
    <body>
    <?php
    // If the form has been submitted, then display the information...
    if(isset($_POST['submit'])) {
    $name = $_POST['name'];
    echo '<p>Your name is ' . $name . '</p>';
    }
    // Otherwise, display the form...
    else {
    echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
    echo ' <label for="name">Your Name...</label>';
    echo ' <input type="text" id="name"/>';
    echo ' <input type="submit" id="submit" value="Submit"/>';
    echo '</form>';
    } // end IF statement
    ?>
    </body>
    </html>

  • #7
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for your reply Elly1 but that form doesn't really do what I need.

    After some research it seems that I need to configure my php.ini file.

    I've put a test file on my server (www.treecycle.com.au/dev/mailtest.php) which does a simple mail test. That seemed to work OK but again I didn't receive the test in my email account.

    I've been in contact with the suppprt people at my ISP and they told me the problem is because the website is on one server but the mail server is on another. I started doing a little research and found that I need to access the php.ini file and configure the sendmail_path. I've put an info.php file on my server and it tells me that the php.ini file is at C:\PHP4\php.ini but I don't know how to access that file. In my FTP client I can access three folders at the top level - db, logs and wwwroot, I can't find the right folder to access the file. I've tried looking in my control panel login as well but in the virtual directory section it just show the same three folders.

    Something else that's confusing me is what the send mail path should be, I've put an info file on the server on my website where the form does work (www.jims-gym.com/info.php) and it shows that there is no value specified in both the sendmail_from and sendmail_path, the info file on the www.treecycle.com.au site (where I'm having trouble with the form) also shows the same.

    Any advice is appreciated.
    Last edited by chocko638; 08-16-2014 at 06:45 AM.

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,128
    Thanks
    80
    Thanked 4,556 Times in 4,520 Posts
    I doubt that we can help. I think you need to go back to your ISP and ask them what the correct php.ini file should look like, given your circumstances.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Yes, I did ask them for further information about the configuration I needed but haven't heard anything back since. I'll contact them again.

    Thanks for your help.

  • #10
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I'm still no closer to sorting this problem out but I've been in touch with the support people at my ISP and they've given me a few different pieces of advice, none of which seems to have helped so far.

    I was researching what to put in my php.ini file and in the process found out that I also needed a .htaccess file to point to the php.ini file. I enquired with my ISP's support and they told me that my website is hosted on a Windows server so I would need a web.config, not .htaccess.

    After some more research it seems that a web.config is associated with an ASP.net application, I'm not using any ASP within my website so I was again stumped as to what I should put in the file.

    While I was working through all that the boss man at my ISP contacted me (after me having a whine about getting confusing single line answers from the support department!) and explained a few things to me. He thinks it's a configuration issue that's to do with requiring authentication against the mail server. He told me that my incoming mail server name would need to be mail.treecycle.com.au and that the email account that I want my form messages sent to should have a password.

    The account I've set up has both that incoming server name and a password as well so I think I've done it right there.

    He also suggested using a mail test PHP script to test for functionality. I tried the script he suggested and it does indeed actually get a test message through to my email account. I had previously tried another test script but it didn't work so I've been trying to compare the two scripts to see what the difference is but as a non-PHP person I can't tell what the difference is (aside from the obvious that the script that doesn't work is only two lines long).

    The script that worked is as follows:
    Code:
    <?php 
        ini_set( 'display_errors', 1 );
        error_reporting( E_ALL );
        $from = "emailtest@treecycle.com.au";
        $to = "enquiries@treecycle.com.au";
        $subject = "PHP Mail Test script";
        $message = "This is a test to check the PHP Mail functionality";
        $headers = "From:" . $from;
        mail($to,$subject,$message, $headers);
        echo "Test email sent";
    ?>
    The script that didn't work is:
    Code:
    <?php
    mail('enquiries@treecycle.com.au','Test mail','The mail function is working!');
    echo 'Mail sent!';
    ?>
    He also mentioned that relaying mail could be causing my problems too but the form is sending to an email account that's on the same domain, my understanding of relaying is when you pass the message through an email server onto a third server? I don't think that's what I'm doing but one of the replies from support did say that the server that hosts my site and the mail server are actually two different servers so now I'm not sure.

    I'm trying to hire a PHP developer close by me to sort this out but I'm not having any luck there either.

    Any suggestions are appreciated.

  • #11
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,128
    Thanks
    2
    Thanked 328 Times in 320 Posts
    Your web hosting may be running on Windows, but what matters is the type of web server. If it's Apache, it would support using a .htaccess file. You would in general, put a local php.ini in the document root folder, though for some web server configurations it only applies to the folder it is in and you may need to put it in other folders if you are making http requests to files in other folders.

    It's likely that if you set php's error_reporting to E_ALL and display_errors to ON, you would be getting feed-back from the mail() statement as to what the problem is.

    If the first short test script worked, what's missing/wrong - in the first post in this thread, is that the From: mail header isn't an email address, and in the second test script, you have no From: mail header, and php is either using no from address or a default from address that's either causing an error on your sending mail server or causing the receiving mail server to discard the email (even if both the sending and receiving mail server are the same.)

    Some of the things the higher up support person stated, have to do with using smtp authentication, which the mail() function cannot do. You would need to either send smtp commands to the mail server or use one of the php mailer classes that does this for you. If he didn't come right out and tell you you needed to use smtp authentication, see what sort of php errors you get after you turn on the error_reporting/display_errors settings.

    edit: also, you should ALWAYS test the value returned by the mail() function. If it's a false value, the sending mail server returned an error to the mail() function, though getting a true value doesn't necessarily mean that the mail will get sent.
    Last edited by CFMaBiSmAd; 09-08-2014 at 05:03 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,128
    Thanks
    80
    Thanked 4,556 Times in 4,520 Posts
    After some more research it seems that a web.config is associated with an ASP.net application
    ASP.NET reads certain items in the web.config file to help set itself up.

    But web.config is no more tied to ASP.NET than .htaccess is tied to PHP.

    Both are used to do such things as redirect URLs to other folders on the server, to change URLs such as "xyz.com/comments/recent" to "www.xyz.com/showComments.php?when=recent", and other mundane but helpful tasks.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #13
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,128
    Thanks
    80
    Thanked 4,556 Times in 4,520 Posts
    The script that didn't work is:
    PHP Code:
    <?php
    mail
    ('enquiries@treecycle.com.au','Test mail','The mail function is working!');
    echo 
    'Mail sent!';
    ?>
    Shame on you! You missed a VERY important part from the working version:
    Code:
        $headers = "From:" . $from;
        mail($to,$subject,$message, $headers);
    The From address needs to be validated, just as your ISP told you! And to do that, it needs to be put in the headers.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #14
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you both for your replies.

    OK, from what I can figure after carefully reading both your replies is that I need to a) specify that the submission from my contact form is coming from a valid source, and b) that information needs to be included in the header and submitted along with the rest of the form submission.

    I've made some changes to my process.php, it now reads as (the additions are in lines 11, 12, 13, 14 and 25):

    PHP Code:
    <?php
    include("global.inc.php");
    $errors=0;
    $error="The following errors occured while processing your form input.<ul>";
    pt_register('POST','Name');
    pt_register('POST','Emailaddress');
    pt_register('POST','Enquiry');
    $Enquiry=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />"$Enquiry);if($Name=="" || $Emailaddress=="" ){
    $errors=1;
    $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
    $from "emailtest@treecycle.com.au";
    $headers "From:" $from;
    ini_set'display_errors');
    error_reportingE_ALL );
    }
    if(
    $errors==1) echo $error;
    else{
    $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
    $message="Name: ".$Name."
    Email address: "
    .$Emailaddress."
    Enquiry: "
    .$Enquiry."
    "
    ;
    $message stripslashes($message);
    mail("test@treecycle.com.au","Form Submitted at your website",$message,"From: phpFormGenerator",$headers);

    header("Refresh: 0;url=http://www.treecycle.com.au/dev/index.html");
    ?><?php 
    }
    ?>
    So I think I'm specifying where the submission is coming from (emailtest@treecycle.com.au) and that the information is in the header which is sent along with the rest of the stuff in the mail statement.

    I've tested it and it still doesn't work so I'm asking if anyone can see why?

    I also included the error reporting code (I'm not sure that the code is in the right place though) but now I'm not sure where to find the error logs. If I look in the logs folder through my FTP client I can find the log files for all the file requests and activity on the site but no error logs. Likewise I also can't find any error logs in my control panel either.

  • #15
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I didn't read all the answers. Did you validate the HTML? All bets are off when HTML errors exist. When form problems persist it often helps to make a copy of your codes in stripped down format. Just a form with little to no surrounding content. Strip the form itself down to one input field and a submit button. Get that much working. Then gradually--step-by-step--add other input fields and finally surrounding content. When ever an error suddenly happens it's likely caused by the last thing you just added, which makes it easier to track down.

    You may want to consider doing the whole thing in one source file:

    <?php

    if($_SERVER['REQUEST_METHOD'] == 'GET'))
    {
    ...show the form
    }
    else
    {
    process the form
    }


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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