Results 1 to 9 of 9

Thread: form upgrade to Php 5.4

  1. #1
    Join Date
    Jun 2010
    Posts
    59
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default form upgrade to Php 5.4

    Hi - I am having a lot of trouble upgrading a PHP form to the newest PHP language. Any help would be greatly appreciated.
    Here is the url: http://www.haepibean.com
    and here is the code:

    Code:
    <script language="JavaScript"> 
    <!--
     
    /***********************************************
    * Required field(s) validation v1.10- By NavSurf
    * Visit Nav Surf at http://navsurf.com
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/
     
    function formCheck(formobj){
    	// Enter name of mandatory fields
    	var fieldRequired = Array("your_email", "age_years", "age_months");
    	// Enter field description to appear in the dialog box
    	var fieldDescription = Array("Email:", "Years:", "Months:");
    	// dialog message
    	var alertMsg = "Please complete the following fields:\n";
    	
    	var l_Msg = alertMsg.length;
    	
    	for (var i = 0; i < fieldRequired.length; i++){
    		var obj = formobj.elements[fieldRequired[i]];
    		if (obj){
    			switch(obj.type){
    			case "select-one":
    				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "select-multiple":
    				if (obj.selectedIndex == -1){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "text":
    			case "textarea":
    				if (obj.value == "" || obj.value == null){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			default:
    			}
    			if (obj.type == undefined){
    				var blnchecked = false;
    				for (var j = 0; j < obj.length; j++){
    					if (obj[j].checked){
    						blnchecked = true;
    					}
    				}
    				if (!blnchecked){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    			}
    		}
    	}
     
    	if (alertMsg.length == l_Msg){
    		return true;
    	}else{
    		alert(alertMsg);
    		return false;
    	}
    }
    // -->
    </script>
    
    
    
    		<form name="dform" action="email.php" method="post" onsubmit="return formCheck(this);">
            <table>
    <tr>
    <td>
    		<input type="hidden" value="thrive@haepibean.com" name="email" />
    		<input type="hidden" value="Contact Form Submission" name="subject"/>
    		email : <input type="text" name="your_email" style="width:215px; height:15px; overflow:hidden; background-color:#ffffff; border:solid; border-width:1px; border-color:#6986B7; font-family: Arial, Helvetica, sans-serif; color:#6986B7; font-size:14; letter-spacing:1px;" />
            
            &nbsp;
             child’s age: years <select name="age_years">
    		<option value="0" style="background-color:#ffffff;">0</option>
    		<option value="1" style="background-color:#ffffff;">1</option>
            <option value="2" style="background-color:#ffffff;">2</option>
            <option value="3" style="background-color:#ffffff;">3</option>
            <option value="4" style="background-color:#ffffff;">4</option>        
     		<option value="5" style="background-color:#ffffff;">5</option>
    		</select>
            
                 
             months <select name="age_months">
    		<option value="0" style="background-color:#ffffff;">0</option>
    		<option value="1" style="background-color:#ffffff;">1</option>
            <option value="2" style="background-color:#ffffff;">2</option>
            <option value="3" style="background-color:#ffffff;">3</option>
              <option value="4" style="background-color:#ffffff;">4</option>
              <option value="5" style="background-color:#ffffff;">5</option>
             <option value="6" style="background-color:#ffffff;">6</option>
            <option value="7" style="background-color:#ffffff;">7</option>
             <option value="8" style="background-color:#ffffff;">8</option>
             <option value="9" style="background-color:#ffffff;">9</option>
             <option value="10" style="background-color:#ffffff;">10</option>
             <option value="11" style="background-color:#ffffff;">11</option>
             <option value="12" style="background-color:#ffffff;">12</option>
    		</select>
            </td>
            <td>
    		
    <input type="image" src="images/hb-learnmorebutton.png" value="submit" name="submit" style="border:none; background:#ffffff; margin-left:10px;" />
    </td></tr></table>
    
    </form>


    email.php:
    Code:
    <?php 
    if(isset($_POST['submit'])) { 
    	
    	# Form declarations
    	$to = "thrive@haepibean.com"; 
    	$subject = "Contact Form Submission";
    	$from = "Contact Form Submission"; 
    	$your_email_field = $_POST['your_email'];
    	$age_years_field = $_POST['age_years'];
    	$age_months_field = $_POST['age_months'];
      
    	$body = "
    	Email: $your_email_field\n
    	Age Years: $age_years_field\n
    	Age Months: $age_months_field\n";
    
    $SpamErrorMessage = "No Websites URLs permitted";
    if (preg_match("/http/i", "$your_email_field")) {echo "$SpamErrorMessage"; exit();}
    if (preg_match("/http/i", "$age_years_field")) {echo "$SpamErrorMessage"; exit();}
    if (preg_match("/http/i", "$age_months_field")) {echo "$SpamErrorMessage"; exit();}
    
    	  
      $success = mail($to, $subject, $body, "From: \"$your_email\" <$your_email_field>");
    
    
    }
    
    
    
    if ($success){
      header('Location: http://haepibean.com/thankyouemail.html');
    } else {
    	header('Location: http://haepibean.com/emailerror.html');
    }
    ?>

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    You need to describe the problem you are trying to solve. We cannot guess.

    Your question is unclear.
    Please provide more information, and be as specific as possible.
    • What do you want to accomplish?
    • What have you already tried?
    • What problems did you encounter?

    Please be sure that you have included all relevant code and/or a link to the page in question.

  3. #3
    Join Date
    Jun 2010
    Posts
    59
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Hi - I dont know the problem. I cannot figure it out. This form works perfectly on PHP 5.3, but GoDaddy just upgraded to PHP 5.4, and it isn't working now.

  4. #4
    Join Date
    Jun 2010
    Posts
    59
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    the form appears to work - takes you to the 'thank you' page, but the email never gets sent.

  5. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by katebellami View Post
    Hi - I dont know the problem. I cannot figure it out. This form works perfectly on PHP 5.3, but GoDaddy just upgraded to PHP 5.4, and it isn't working now.
    "isn't working" is not useful information. Describe what happens, as opposed to what you expect to happen.

    Quote Originally Posted by katebellami View Post
    the form appears to work - takes you to the 'thank you' page, but the email never gets sent.
    There we go.

    There could be any number of things happening here. A few things you might try in your code:
    PHP Code:
    $success mail($to$subject$body"From: \"$your_email\" <$your_email_field>"); 
    • I don't see the variable $your_email defined anywhere in the code you posted.
    • Your From header is missing a trailing CRLF (\r\n).


    If you're getting redirected to the "thanks" page, it would seem that $success is true - and, therefore, that your email is being submitted to the mail server. The issues I pointed out above might be causing it to be discarded before being sent.

    If it is being sent, then it might be being dropped as spam along the way. Generally speaking, the email address in the "From" header should be from the same domain that actually sent the email, so using the visitor's email address can sometimes lead to problems. You should either add a "Sender" header that includes an address from your domain, or put such an address in the "From" header and put the user's address in a "Reply-To" header.

    If these changes don't solve anything, then I would recommend enabling error reporting (use error_reporting(-1); ini_set('display_errors',1); at the top of your script) and commenting out the header() calls (so you can see what is happening).

  6. #6
    Join Date
    Jun 2010
    Posts
    59
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Hi - the issue was confirm by GoDaddy to be changes in the new Php5.4 which they are running on now (again it worked perfectly in earlier versions).

    The issue is the the email actually being sent. It isnt being spammed. it just isnt being actually sent, which is odd because, as you stated, you are taken the thank you page when you click submit (and required field portion of script is working fine as well).

    Ive simplified the portion of the script that seems to have the issue or need to be 'upgraded' for php 5.4. You will see in red where 'your_email' is defined.

    form code:
    Code:
    <form name="dform" action="email.php" method="post" onsubmit="return formCheck(this);">
            <table>
    <tr>
    <td>
    		<input type="hidden" value="thrive@haepibean.com" name="email" />
    		<input type="hidden" value="Contact Form Submission" name="subject"/>
    		email : <input type="text" name="your_email" style="width:215px; height:15px; overflow:hidden; background-color:#ffffff; border:solid; border-width:1px; border-color:#6986B7; font-family: Arial, Helvetica, sans-serif; color:#6986B7; font-size:14; letter-spacing:1px;" />
            
            &nbsp;
             child’s age: years <select name="age_years">
    		<option value="0" style="background-color:#ffffff;">0</option>
    		<option value="1" style="background-color:#ffffff;">1</option>
            <option value="2" style="background-color:#ffffff;">2</option>
            <option value="3" style="background-color:#ffffff;">3</option>
            <option value="4" style="background-color:#ffffff;">4</option>        
     		<option value="5" style="background-color:#ffffff;">5</option>
    		</select>
            
                 
             months <select name="age_months">
    		<option value="0" style="background-color:#ffffff;">0</option>
    		<option value="1" style="background-color:#ffffff;">1</option>
            <option value="2" style="background-color:#ffffff;">2</option>
            <option value="3" style="background-color:#ffffff;">3</option>
              <option value="4" style="background-color:#ffffff;">4</option>
              <option value="5" style="background-color:#ffffff;">5</option>
             <option value="6" style="background-color:#ffffff;">6</option>
            <option value="7" style="background-color:#ffffff;">7</option>
             <option value="8" style="background-color:#ffffff;">8</option>
             <option value="9" style="background-color:#ffffff;">9</option>
             <option value="10" style="background-color:#ffffff;">10</option>
             <option value="11" style="background-color:#ffffff;">11</option>
             <option value="12" style="background-color:#ffffff;">12</option>
    		</select>
            </td>
            <td>
    		
    <input type="image" src="images/hb-learnmorebutton.png" value="submit" name="submit" style="border:none; background:#ffffff; margin-left:10px;" />
    </td></tr></table>
    
    </form>

    And here is the simplified code where the issue seems to lie in the email.php file:

    PHP Code:
    <?php 
    if(isset($_POST['submit'])) { 
        
        
    # Form declarations
        
    $to "thrive@haepibean.com"
        
    $subject "Contact Form Submission";
        
    $from "Contact Form Submission"
        
    $your_email_field $_POST['your_email'];
        
    $age_years_field $_POST['age_years'];
        
    $age_months_field $_POST['age_months'];
      
        
    $body "
        Email: 
    $your_email_field\n
        Age Years: 
    $age_years_field\n
        Age Months: 
    $age_months_field\n";

          
      
    $success mail($to$subject$body"From: \"$your_email\" <$your_email_field>");

    }

    if (
    $success){
        
    header('Location: [url]http://haepibean.com/thankyouemail.html');[/url]
    } else {
        
    header('Location: [url]http://haepibean.com/emailerror.html');[/url]
    }
    ?>
    I am not sure what you mean by this "Your From header is missing a trailing CRLF (\r\n)."

    Im working in dreamweaver, and it is giving me no error messages.
    Last edited by traq; 12-03-2013 at 06:05 PM. Reason: added code tags

  7. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by katebellami View Post
    The issue is the the email actually being sent. It isnt being spammed. it just isnt being actually sent, which is odd because, as you stated, you are taken the thank you page when you click submit (and required field portion of script is working fine as well).
    The mail() function doesn't actually send your email. It submits the message to the mail server, and returns true if the mail server accepts it. PHP has absolutely no idea what happens after that.

    Quote Originally Posted by katebellami View Post
    … You will see in red where 'your_email' is defined.
    [CODE]email : <input type="text" name="your_email" style="width:215px; height:15px; overflow:hidden; background-color:#ffffff; border:solid; border-width:1px; border-color:#6986B7; font-family: Arial, Helvetica, sans-serif; color:#6986B7; font-size:14; letter-spacing:1px;" />
    No, that's the form field; I'm talking about the PHP variable $your_email (in your call to the mail() function):
    Code:
    $success = mail($to, $subject, $body, "From: \"$your_email\" <$your_email_field>");
    Quote Originally Posted by katebellami View Post
    I am not sure what you mean by this "Your From header is missing a trailing CRLF (\r\n)."
    All email headers end with CRLF. (A "carriage return, line feed." In PHP, you write it like "\r\n" (n.b., you must use double-quotes; single-quotes won't work).) You need to add them after each of the headers you pass to mail():
    PHP Code:
    mail$to,$subject,$body,"From: my@email.com\r\n" ); 
    Quote Originally Posted by katebellami View Post
    Im working in dreamweaver, and it is giving me no error messages.
    DreamWeaver is not suitable for debugging PHP.

    During development, you should enable PHP's error reporting features. As I mentioned above, you'll have to comment out your header calls in order to see the error messages.

    It might also be helpful to use var_dump to inspect all of your variables, to make sure they contain the values you think they do.

    There are code editors that can highlight parse errors (if you have a local php installation) and also provide many other helpful features. I use and highly recommend Komodo Edit, which is free (as in beer) and works on Linux, Mac, and Windows.
    Last edited by traq; 11-26-2013 at 01:13 AM.

  8. #8
    Join Date
    Jun 2010
    Posts
    59
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your help. Unfortunately it has something to do with the form PHP not being compatible with PHP5. It works perfectly in PHP4 environment. STarting over from scratch.

  9. #9
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    What are you basing this on? Have you investigated the possibilities I mentioned? Have you enabled error reporting? Have you tried fixing the email headers?

    To clarify, the script you posted is perfectly valid in php 5.4. You said it was "simplified," so you may have left out a part that causes problems (have you tested this "simplified" code to make sure it still demonstrates the problem?), but the only things "wrong" with it is the undeclared variable.

    In addition, if GoDaddy claims that the issue is being caused by the upgrade to 5.4, then they should be able to tell you what, specifically, is causing it. If they cannot, then they are simply guessing.

    Given the information you've shared, my best guess would still be that your message is being dropped as "spam"/"corrupted" at some point during its delivery. (This is also something GoDaddy likely doesn't know - perhaps they know if they sent it or not, but they probably aren't tracking it. In fact, if they were, then they would be able to tell you what happened to it and where.)

Similar Threads

  1. Need php5 upgrade help again, please..
    By BLiZZaRD in forum PHP
    Replies: 3
    Last Post: 07-29-2013, 10:18 PM
  2. How to Upgrade Image Crawler
    By Ponder in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 06-08-2012, 08:27 PM
  3. Will this forum upgrade?
    By C0ldf1re in forum The lounge
    Replies: 0
    Last Post: 04-01-2010, 10:52 AM
  4. RAM Upgrade Problems?
    By josephtaylor1995 in forum Computer hardware and software
    Replies: 5
    Last Post: 04-05-2009, 10:20 PM
  5. Workstation upgrade/change
    By nate51 in forum Computer hardware and software
    Replies: 2
    Last Post: 09-22-2008, 12:49 PM

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
  •