www.webdeveloper.com
Results 1 to 5 of 5

Thread: PHP form sending blank emails

Hybrid View

  1. #1
    Join Date
    Mar 2007
    Posts
    14

    PHP form sending blank emails

    Hi,

    I'm an absolute beginner with PHP and searched the web for a contact form. I followed the steps and the form works fine, emailing me when someone fills it in and then going to a success page once it's sent. I set this up yesterday.

    Today however I have received a blank mail, as though the form has sent without being filled in.

    Below is the PHP and HTML I'm using. Any advice on how to stop it sending blank emails would be really appreciated. I really don't know what I'd need to do to stop this.

    PHP Code:
    <?php
     $name 
    $_POST['name'];
     
    $email $_POST['email'];
     
    $message $_POST['message'];
     
    $formcontent="From: $name \n Message: $message";
     
    $recipient "me@mywebsite.com, alternative@mywebsite.com";
     
    $subject "Message From mywebsite.com Contact Form";
     
    $mailheader "From: $email \r\n";
     
    mail($recipient$subject$formcontent$mailheader) or die("Error!");
     print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=../pages/contact_success.html\">";
    ?>
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    		<meta name="description" content="Send your questions or feedback to Home Of Katkin.">
    		
    		<link rel="stylesheet" type="text/css" href="../css/homeofkatkin_stylesheet.css">
    		<link rel="stylesheet" href="../css/contact.css" type="text/css" media="screen" />
    		
    		<title>Home of Katkin - Contact: Send your questions or feedback to Home Of Katkin.</title>
    		
    		<script type="text/javascript">
    
    		  var _gaq = _gaq || [];
    		  _gaq.push(['_setAccount', 'UA-20966624-6']);
    		  _gaq.push(['_trackPageview']);
    
    		  (function() {
    		    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    		    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    		    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    		  })();
    
    		</script>
    	</head>
    	<body>
    		<div id="container">
    			<!-- Header -->
    			<div id="header">
    				<span><a href="../pages/welcome.html">Welcome</a></span>
    				<span><a href="../pages/portfolio.html">Portfolio</a></span>
    				<span><a href="../pages/shop.html">Shop</a></span>
    				<!-- Store temporarily down
    				<span><a href="http://homeofkatkin.com/store/index.php?osCsid=194d30bf0273518b08d97099cd4f1a69">Shop</a></span>
    				<span><a href="http://homeofkatkin.com/store/account.php?osCsid=194d30bf0273518b08d97099cd4f1a69">My Account</a></span>
        		    <span><a href="http://homeofkatkin.com/store/shopping_cart.php?osCsid=194d30bf0273518b08d97099cd4f1a69">Basket</a></span>
    				<span><a href="http://homeofkatkin.com/store/contact_us.php">Contact</a></span> -->
    				<span><a href="../pages/contact.html">Contact</a></span>
    				<span><a href="../pages/links.html">Links</a></span>
    			</div>
    			
    			<!-- Content -->
    			<div id="content">
    			  <div id="contents">
    				<h1>Contact</h1>
    				<form id="form" action="../php/contact.php" method="post">
    					Your name:<br>
    					<input type="text" name="name" size="40"><br><br>
    						
    					Your email<br>
    					<input type="text" name="email" size="40"><br><br>
    						
    					Your comments or questions:<br>
    					<textarea name="message" rows="10" cols="40"></textarea><br><br>
    						
    					<input type="submit" value="Send"> <input type="reset" value="Clear">
    				</form>
    				<div id="image">
    					<img src="../images/contact/studio.jpg" alt="Katy's studio" title="Katy's studio" />
    				</div>			
    			  </div>
    			</div>
    			<div id="clear-footer"></div>	
    		</div>
    		<div id="footer">
    			&copy; Home of Katkin 2010 - 2011
    		</div>
    	</body>
    </html>
    Many thanks

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    I don't see anything for form validation (ie, making sure a field is filled out, making sure it's only letters for name, etc.) So anyone could bring up the form and hit SUBMIT without filling anything out. This _could_ explain what happened, but it's just a guess.

  3. #3
    Join Date
    Mar 2007
    Posts
    14
    I never thought of that, as I say, I'm new to PHP.

    I've searched for a tutorial on doing this. Do you think the method here would be suitable.

    Sorry for asking what is probably a naive question but I don't know php so don't know how to tell between good processes and bad processes.

    Many thanks.

  4. #4
    Join Date
    Dec 2011
    Posts
    87
    Quote Originally Posted by satkin2 View Post
    I never thought of that, as I say, I'm new to PHP.

    I've searched for a tutorial on doing this. Do you think the method here would be suitable.

    Sorry for asking what is probably a naive question but I don't know php so don't know how to tell between good processes and bad processes.

    Many thanks.
    If you can understand the tutorial then use it. I personally prefer using javascript for validation but that tutorial will suffice.

    If you get stuck just post a message.

  5. #5
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Quote Originally Posted by satkin2 View Post
    I never thought of that, as I say, I'm new to PHP.

    I've searched for a tutorial on doing this. Do you think the method here would be suitable.

    Sorry for asking what is probably a naive question but I don't know php so don't know how to tell between good processes and bad processes.

    Many thanks.
    Everybody has to start somewhere, right? :) We all did.

    There is client-side validation (JavaScript), and there is server-side validation (PHP, or whatever dynamic language you're using.) There are good and bad things about both; it's up to you.

    Client-side validation GOOD: it saves bandwidth and server CPU.
    Client-side validation BAD: JavaScript can be disabled in the browser, bypassing form validation.
    Server-side validation GOOD: it can't be bypassed.
    Server-side validation BAD: you have to actually submit the form in order to validate the entries, which takes up network bandwidth and server CPU time/resources.

    These are over-simplified, of course, but you get the basic principle.

    If you have the time (and patience), do both. The JavaScript (client-side) validation will be used in 96% of submissions, and the client-side can be a redundant back-up validator for those who choose to disable JavaScript (or if JavaScript is not an option.)

    Another thing, for those of the mind: Set it so that the form submits via JavaScript - that way, if JavaScript is disabled, a majority of the forms cannot be submit. There are ways around this, of course, but it's a thought.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles