Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Contact Form not submitting or Sending emails
Old 01-03-2011, 07:57 AM Contact Form not submitting or Sending emails
Junior Talker

Posts: 4
Name: Michael
Trades: 0
I have a contact form that is not submitting to the table in my database, or sending out automatic emails. Not only is it not doing either of these but it is also not echoing any errors. Could someone check my coding below and help me get this script working fully. Thanks in advance.

PHP Code:
<?php
ob_start
();
session_start();
// Include the configuration file for error management and such.
require_once ('includes/config.inc.php'); 
if (isset(
$_POST['send'])) { // Handle the form.
 
require_once ('includes/mysql_connect.php'); // Connect to the database.
 // Check for a name.
 
if (eregi ('^[[:alpha:]\.\' \-]{2,40}$'stripslashes(trim($_POST['name'])))) {
  
$n escape_data($_POST['name']);
 } else {
  
$n FALSE;
  echo 
'<p>Please enter your name!</p>';
 }
 
 
// Check for an email address.
 
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,40}$'stripslashes(trim($_POST['email'])))) {
  
$e escape_data($_POST['email']);
 } else {
  
$e FALSE;
  echo 
'<p>Please enter a valid email address!</p>';
 }
 
// Check for submitted comments.
 
if (eregi ('^[[:alnum:]\.\,\;\'\-]{4,600}$'stripslashes(trim($_POST['comments'])))) {
  
$c escape_data($_POST['comments']);
  } else {
   
$c FALSE;
  echo 
'<p>Please enter your comments!</p>';
 }
 
 if (
$n && $e && $c) { // If everything's OK.
 
   // Add the message.
   
$query "INSERT INTO comments (email, name, comments, message_date) VALUES ('$e', '$n', '$c', NOW() )";  
   
$result mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " mysql_error());
   if (
mysql_affected_rows() == 1) { // If it ran OK.
 
    // Send the email.
    
$body "Thank you for your message $n, we will reply to you at $e about $c.";
    
mail($_POST['email'], 'Website Message'$body);
 
    
// Send the email.
    
$body "A message has been received from $n regarding $c.  Their email address is $e.";
    
mail(my-name@mywebsite.com'New Message'$body);
 
    
// Finish the page.
    
echo '<p>Thank you $n for contacting us about $c! An email has been sent to $e acknowledging our receipt of your comments.</p>';
    include (
'includes/foot.html'); // Include the HTML footer.
    
exit();    
 
   } else { 
// If it did not run OK.
    
echo '<p>We did not receive your message due to a system error. We apologize for any inconvenience.</p>'
   }  
 
 } else { 
// If one of the data tests failed.
  
echo '<p>Please try again.</p>';  
 }
 
mysql_close(); // Close the database connection.
// End of the main Submit conditional.
?>
Alley Cat is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-03-2011, 11:52 AM Re: Contact Form not submitting or Sending emails
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Is there any particular reason why you are using output buffering? There may be a fatal error before you get to the validation points of the scripts. Try outputing test points (echo 1 after each file include.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 01-03-2011, 04:14 PM Re: Contact Form not submitting or Sending emails
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Comment out ob_start and have a look at http://uk2.php.net/manual/en/function.ob-start.php before you use it. Concentrate on one problem at a time: put the email code in a separate little script and see if it sends to a test address. Once that's ok, look at the rest of it. As said above, echo meaningful strings and values at various points -- that should let you know where it's going wrong, then you can more easily sort the problem.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 01-04-2011, 10:29 AM Re: Contact Form not submitting or Sending emails
Junior Talker

Posts: 4
Name: Michael
Trades: 0
Thanks for the advice guys, but having only learned PHP MYSQL from a Visual QuickPro book I don't know how to do any of the things you have suggested, but I have decided to continue using the original contact form, which does send out emails, and echoes that the message has been received, but does not send to table in database
Alley Cat is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Contact Form not submitting or Sending emails
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14439 seconds with 12 queries