Hi, firstly many thanks for the article, it's the best by far that I've seen.
Secondly I apologise in advance to the more seasoned programmer who may feel that is a basic question, but I'm relatively new to this so please bear with me.
I'm wanting to adapt this to use as a form submission script, but just so I understand how everything works I've kept the HTML form as per the example only changing the PHP script as shown below.
The code correctly saves the data to a mySQL database. But the problem I'm having is that upon clicking 'Send email' I, for a fraction of a second, receive the 'Sending mail' message, before receiving the 'There was a problem...' error message. Because of this, the fields in the form are not cleared and I do not receive the final 'Thank you' message.
I've been working on this for a few days now and I just can't seem to get the process to work correctly.
I just wondered whether someone could possibly please take a look at this and let me know where i'm going wrong.
Many thanks and kind regards
Secondly I apologise in advance to the more seasoned programmer who may feel that is a basic question, but I'm relatively new to this so please bear with me.
I'm wanting to adapt this to use as a form submission script, but just so I understand how everything works I've kept the HTML form as per the example only changing the PHP script as shown below.
<?php
include("admin/link.php");
include("admin/opendb.php");
// Read the form values
$success = false;
$senderName = isset( $_POST['senderName'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['senderName'] ) : "";
$senderEmail = isset( $_POST['senderEmail'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";
$query = "INSERT INTO `contact` (senderName, senderEmail, message) VALUES ('$senderName', '$senderEmail', '$message')";
$result = mysql_query($query); //query executes
// Return an appropriate response to the browser
if ( isset($_GET["ajax"]) )
{
echo $success ? "success" : "error";
} else {
?>
<html>
<head>
<title>Thanks!</title>
</head>
<body>
<?php if ( $success ) echo "<p>Thanks for sending your message! We'll get back to you shortly.</p>" ?>
<?php if ( !$success ) echo "<p>There was a problem sending your message. Please try again.</p>" ?>
<p>Click your browser's Back button to return to the page.</p>
</body>
</html>
<?php
}
?>
The code correctly saves the data to a mySQL database. But the problem I'm having is that upon clicking 'Send email' I, for a fraction of a second, receive the 'Sending mail' message, before receiving the 'There was a problem...' error message. Because of this, the fields in the form are not cleared and I do not receive the final 'Thank you' message.
I've been working on this for a few days now and I just can't seem to get the process to work correctly.
I just wondered whether someone could possibly please take a look at this and let me know where i'm going wrong.
Many thanks and kind regards


