PHP Validation error

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 1853 Views - Last Post: 21 September 2011 - 10:21 PM Rate Topic: -----

#16 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2503
  • View blog
  • Posts: 8,564
  • Joined: 08-August 08

Re: PHP Validation error

Posted 19 September 2011 - 01:01 PM

View Postswim_fan08, on 19 September 2011 - 12:01 PM, said:

Yes, I do understand its a waste of processor space. I was just posting up what I had that works and would like to stick to that as closely as possible, but with validation.

If it worked you wouldn't need to post anything. You'd be done. If you're not going to use good advice this is going to take longer and be harder than it needs to be.

View Postswim_fan08, on 19 September 2011 - 12:01 PM, said:

Since when I actually ran my updated code with the validation, it wouldnt send an actual email after I had tested each of the fields by leaving them blank.

Then that's the code we need to see, along with any errors/warnings.
Was This Post Helpful? 1
  • +
  • -

#17 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5723
  • View blog
  • Posts: 22,635
  • Joined: 23-August 08

Re: PHP Validation error

Posted 19 September 2011 - 01:43 PM

View Postswim_fan08, on 19 September 2011 - 03:04 PM, said:

If possible, is there a tutorial that I can use that goes along with which version of php I am using? (Iam using php 6 and thats what I understand and works with my webhost).


Uh...there *IS* no PHP 6, dude. Here are the downloads for the current versions: http://php.net/downloads.php

Notice the utter lack of a PHP 6.
Was This Post Helpful? 0
  • +
  • -

#18 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2935
  • View blog
  • Posts: 7,689
  • Joined: 08-June 10

Re: PHP Validation error

Posted 20 September 2011 - 01:34 AM

View Postswim_fan08, on 19 September 2011 - 09:04 PM, said:

(Iam using php 6 and thats what I understand and works with my webhost).

I doubt that. PHP 6 development is currently postponed for an unknown period of time, PHP 5.4 is still in alpha stage. so the lates version you can have is PHP 5.3 but most ISPs still use PHP 5.2.
Was This Post Helpful? 0
  • +
  • -

#19 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Re: PHP Validation error

Posted 20 September 2011 - 10:19 AM

View PostCTphpnwb, on 19 September 2011 - 02:01 PM, said:

View Postswim_fan08, on 19 September 2011 - 12:01 PM, said:

Yes, I do understand its a waste of processor space. I was just posting up what I had that works and would like to stick to that as closely as possible, but with validation.

If it worked you wouldn't need to post anything. You'd be done. If you're not going to use good advice this is going to take longer and be harder than it needs to be.

View Postswim_fan08, on 19 September 2011 - 12:01 PM, said:

Since when I actually ran my updated code with the validation, it wouldnt send an actual email after I had tested each of the fields by leaving them blank.

Then that's the code we need to see, along with any errors/warnings.


This is a different approach that I took, and I get an error : Parse error: syntax error, unexpected '@' in /home/a9577046/public_html/email.php on line 22.


<?php
if(isset($_POST['submit']))
{
	if (empty($_POST['name']))
	{$errors[] = 'Please enter a name';}
	
	if (empty($_POST['subject']))
	{$errors[] = 'Please enter a subject';}
	
	if (empty($_POST['text']))
	{$errors[] = 'Please enter your comments.';}
	
	if (empty($_POST['email']))
	{$errors[] = 'Please enter an e-mail';}
	elseif (!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i", $_POST['email']))
	{$errors[] = 'Please enter a valid e-mail address';}		
	{
	
	if (count($errors) == 0)			
	{				 
		// Your OR Receiver email address		 
		$to=  myemailaddress@gmail.com;				
		
		// Process form				
		$headers = "MIME-Version: 1.0\r\n";							
		$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";							
		$headers.= "From: XXXXX\r\nReply-To: myemailaddress@gmail.com";											
		
		$subject = $_POST['subject'];	
		$final_message = "	Name - " . $_POST['name']. " email - ".$_POST['email']. " Message-".$_POST['text']; 			 										
		
		if (mail($to, $subject, $final_message, $headers) )				
		{	echo " Thankyou! - Your feedback has been sent! ";	}				
		else				
		{	echo " Thankyou! - We could not send email. Please try later! ";	}					
	}
	else
	{ 	var_dump($errors);	}
}
else
{
?>
<form method="post" action="email.php">
	 <label for="name">* Name:</label> 
	 <input name="name" type="text" class="input_field" id="name" maxlength="40" />                          	
	 <div class="cleaner_h10"></div>
	 
	 <label for="subject">* Subject:</label> 
	 <input name="subject" type="text" class="input_field" id="subject" maxlength="40" />                          	
	 <div class="cleaner_h10"></div>
	 
	 <label for="email">* Email:</label>
	  <input name="email" type="text" class="input_field" id="email" maxlength="40" />                          	
	  <div class="cleaner_h10"></div>
	  
	   <div class="col_w340 float_r">                                                    
	   <label for="text">* Message:</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea>                            		       <div class="cleaner_h10"></div>                                                        
	   <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" />                            
	   <input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" />                                                  
</form>
<?
	}
?> 


Was This Post Helpful? 0
  • +
  • -

#20 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2935
  • View blog
  • Posts: 7,689
  • Joined: 08-June 10

Re: PHP Validation error

Posted 20 September 2011 - 10:35 AM

strings should be quoted.
Was This Post Helpful? 0
  • +
  • -

#21 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Re: PHP Validation error

Posted 20 September 2011 - 05:54 PM

I went ahead and took a different approach, I think its a little better. Now my only problem is that it says that it sends, but when I check I get no email.

    <?php  
      
        if (isset($_POST['Submit'])) {  
      
            if ($_POST['name'] != "") {  
                $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);  
                if ($_POST['name'] == "") {  
                    $errors .= 'Please enter a valid name.<br/><br/>';  
                }  
            } else {  
                $errors .= 'Please enter your name.<br/>';  
            }  
      
            if ($_POST['email'] != "") {  
                $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);  
                if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {  
                    $errors .= "$email is <strong>NOT</strong> a valid email 

address.<br/><br/>";  
                }  
            } else {  
                $errors .= 'Please enter your email address.<br/>';  
            }  

            if ($_POST['message'] != "") {  
                $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);  
                if ($_POST['message'] == "") {  
                    $errors .= 'Please enter a message to send.<br/>';  
                }  
            } else {  
                $errors .= 'Please enter a message to send.<br/>';  
            }  
      
            if (!$errors) {  
                $mail_to = 'myemailaddress@gmai.com';  
                $subject = 'New Mail from Form Submission';  
                $message  = 'From: ' . $_POST['name'] . "\n";  
                $message .= 'Email: ' . $_POST['email'] . "\n";  
                $message .= "Message:\n" . $_POST['message'] . "\n\n";  


		if (mail($mail_to, $subject, $message, $headers) )				
		{	echo " Thank you! - Your feedback has been sent! ";	}		

		
             } else {  
                echo '<div style="color: red">' . $errors . '<br/></div>';  
            }  
        }  
    ?>  
      
    <form name="form1" method="post" action="test.php">  
    Name: <br/>  
    <input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="50" 

/><br/><br/>  
    Email Address: <br/>  
    <input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="50"/> 

<br/><br/>  
    Message: <br/>  
    <textarea name="message" rows="5" cols="50"><?php echo $_POST['message']; ?></textarea>  
    <br/>  
    <input type="submit" name="Submit" />  
    </form>  





Was This Post Helpful? 0
  • +
  • -

#22 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5723
  • View blog
  • Posts: 22,635
  • Joined: 23-August 08

Re: PHP Validation error

Posted 21 September 2011 - 03:19 AM

Did you check your spam folder?
Was This Post Helpful? 0
  • +
  • -

#23 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 9153
  • View blog
  • Posts: 33,962
  • Joined: 27-December 08

Re: PHP Validation error

Posted 21 September 2011 - 08:23 AM

The mail() function only assures that the message is delivered to the server to be sent. It does not guarantee that it will be sent. Check to see if anything is in the logs about it.
Was This Post Helpful? 0
  • +
  • -

#24 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Re: PHP Validation error

Posted 21 September 2011 - 10:54 AM

View PostJackOfAllTrades, on 21 September 2011 - 04:19 AM, said:

Did you check your spam folder?


Yes, I did.

View Postmacosxnerd101, on 21 September 2011 - 09:23 AM, said:

The mail() function only assures that the message is delivered to the server to be sent. It does not guarantee that it will be sent. Check to see if anything is in the logs about it.


Nothing in the logs.
Was This Post Helpful? 0
  • +
  • -

#25 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Re: PHP Validation error

Posted 21 September 2011 - 11:04 AM

I changed some more things around, now I get this error I get : Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a9577046/public_html/mail.php on line 39

I think I may be mixing my double quotes with single quotes.


<?php
if(isset($_POST['submit']))
{
	if ($_POST['name'] != "") {  
                $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);  
                if ($_POST['name'] == "") {  
                    $errors .= 'Please enter a valid name.<br/><br/>';  
                }  
            } else {  
                $errors .= 'Please enter your name.<br/>';  
            }  
      
            if ($_POST['email'] != "") {  
                $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);  
                if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {  
                    $errors .= "$email is <strong>NOT</strong> a valid email 

address.<br/><br/>";  
                }  
            } else {  
                $errors .= 'Please enter your email address.<br/>';  
            }  
            
            if ($_POST['message'] != "") {  
                $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);  
                if ($_POST['message'] == "") {  
                    $errors .= 'Please enter a message to send.<br/>';  
                }  
            } else {  
                $errors .= 'Please enter a message to send.<br/>';  
            }  
	
	if (count($errors) == 0)			
	{				 
		// Your OR Receiver email address		 
		$to='myemailaddress@gmail.com';				
		
		// Process form				
		$headers = "MIME-Version: 1.0\r\n";						

	
		$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";			

				
		$headers.= "From:$_POST['name']\r\n Reply-To: $_POST['email'}";			

								
		
		$subject = $_POST['subject'];	
		$message = "	Name - " . $_POST['name']. " email - ".$_POST['email']. " 

Message-".$_POST['text']; 			 						

				


            if (!$errors) {  
                $mail_to =  'Email: ' . $_POST['email'] . "\n";  
                $subject = 'New Mail from Form Submission';  
                $message  = 'From: ' . $_POST['name'] . "\n";  
                $message .= 'Email: ' . $_POST['email'] . "\n";  
                $message .= 'Homepage: ' . $_POST['homepage'] . "\n";  
                $message .= "Message:\n" . $_POST['message'] . "\n\n";  
                mail($to, $subject, $message);  
		
		if (mail($to, $subject, $message, $headers) )				
		{	echo " Thank you! - Your feedback has been sent! ";	}		

		
           echo "Thank you for your email!<br/><br/>";  
            } else {  
                echo '<div style="color: red">' . $errors . '<br/></div>';  
            }  
          
	else
	{ 	var_dump($errors);	}
}
else
{
?>
<form method="post" action="#">
	 <label for="name">* Name:</label> 
	 <input name="name" type="text" class="input_field" id="name" maxlength="40" />      

                    	
	 <div class="cleaner_h10"></div>
	 
                     	 <div class="cleaner_h10"></div>
	 
	 <label for="email">* Email:</label>
	  <input name="email" type="text" class="input_field" id="email" maxlength="40" />   

                       	
	  <div class="cleaner_h10"></div>
	  
	   <div class="col_w340 float_r">                                                    
	   <label for="text">* Message:</label> <textarea id="text" name="text" rows="0" 

cols="0" class="required"></textarea>                            		       <div 

class="cleaner_h10"></div>                                                        
	   <input type="submit" class="submit_btn float_l" name="submit" id="submit" 

value="Send" />                            
	   <input type="reset" class="submit_btn float_r" name="reset" id="reset" 

value="Reset" />                                                    </      div>             

                              
</form>
<?
	}
?>



Was This Post Helpful? 0
  • +
  • -

#26 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2503
  • View blog
  • Posts: 8,564
  • Joined: 08-August 08

Re: PHP Validation error

Posted 21 September 2011 - 07:28 PM

Change this line:
        $headers.= "From:$_POST['name']\r\n Reply-To: $_POST['email'}";        


to this:
        $headers.= "From:".$_POST['name']."\r\n Reply-To: ".$_POST['email'];        


Was This Post Helpful? 0
  • +
  • -

#27 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2935
  • View blog
  • Posts: 7,689
  • Joined: 08-June 10

Re: PHP Validation error

Posted 21 September 2011 - 10:21 PM

2 other options to correct that error:
$headers.= "From:{$_POST['name']}\r\n Reply-To: {$_POST['email']}";

$headers.= sprintf("From:%s\r\n Reply-To: %s", $_POST['name'], $_POST['email']);

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2