I have a contact form in a popup div. I want the contact form to redirect to the popup div with an error or a successful message when form is completed obviously depending if message was sent NOT A PAGE. Please can someone help me.

<?php

//set variable error var

$er = 0;

//enter the website the contact form is on
$website =  'J Computing Consultants Ltd';

//Set all POST variables

$name = $_POST['name'];
$email = $_POST['email'];
$message1 = $_POST['message'];
$display = $message1;
$nameto = "Customer Service";  
$from = $email;  
$namefrom = "jcomputingconsultants.co.uk";  

//check name
    if(!ereg("^[A-Za-z'.-]", $name)) {
        $er = 1;
    }
//check email
    if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email)) {
        $er = 1;
    }
//check message
    if(!ereg("^[a-zA-Z0-9-]", $message1)) {
        $er = 1;
    }
if ($er == 1)    {
    header("Location: contacterror.php"); //error path if form does not send successfully.
}

if ($er == 0)    {    

    // strip slashes if magic quotes on (default).
    if (get_magic_quotes_gpc()) {
            $message1 = stripslashes( $message1 );
        }

    //wordwrap
    $message1 =wordwrap($message1, 70);

    // enter the mail address the form is sent to
    $to  = 'webmaster@jcomputingconsultants.co.uk';


    // subject
    $subject = "$website Online Query";

    // message
    $message = "
    <html>
    <head>
      <title>$website Online Query</title>
    </head>
    <body>
      <p><b>Message from:</b> $name</p>
      <p><b>E-mail Address:</b> $email</p>
      <p><b>Message:</b> $display</p>


    </body>
    </html>
    ";


authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);  
// success path con completion of the form.
header("Location: contactsuccess.php");

}

/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

//This will send an email using auth smtp and output a log array
//logArray - connection,




    /* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

    //This will send an email using auth smtp and output a log array
    //logArray - connection,

    function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message) {
    //SMTP + SERVER DETAILS
    /* * * * CONFIGURATION START * * * */
    $smtpServer = "127.0.0.1";
    $port = "25";
    $timeout = "30";
    $username = "...";
    $password = "...";
    $localhost = "localhost";
    $newLine = "\r\n";
    /* * * * CONFIGURATION END * * * * */

    //Connect to the host on the specified port
    $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
    $smtpResponse = fgets($smtpConnect, 515);
    if(empty($smtpConnect))
    {
    $output = "Failed to connect: $smtpResponse";
    return $output;
    }
    else
    {
    $logArray['connection'] = "Connected: $smtpResponse";
    }



    //Say Hello to SMTP
    fputs($smtpConnect, "EHLO $localhost" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['heloresponse'] = "$smtpResponse";

    //Request Auth Login
    fputs($smtpConnect,"AUTH LOGIN" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['authrequest'] = "$smtpResponse";

    //Send username
    fputs($smtpConnect, base64_encode($username) . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['authusername'] = "$smtpResponse";

    //Send password
    //fputs($smtpConnect, base64_encode($password) . $newLine);
    fputs($smtpConnect, base64_encode($password) . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['authpassword'] = "$smtpResponse";

    //Email From
    fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['mailfromresponse'] = "$smtpResponse";

    //Email To
    fputs($smtpConnect, "RCPT TO: $to" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['mailtoresponse'] = "$smtpResponse";

    //The Email
    fputs($smtpConnect, "DATA" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['data1response'] = "$smtpResponse";

    //Construct Headers
    $headers = "MIME-Version: 1.0" . $newLine;
    $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
    $headers .= "To:" . $newLine;
    $headers .= "From:$email" . $newLine;

    fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['data2response'] = "$smtpResponse";

    // Say Bye to SMTP
    fputs($smtpConnect,"QUIT" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['quitresponse'] = "$smtpResponse";

    //print "<PRE>";
    //var_dump($logArray); 
}

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.