Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6207063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:33:44+00:00 2026-05-24T05:33:44+00:00

I have a system where the user sends an email using a form (simple).

  • 0

I have a system where the user sends an email using a form (simple).

HTML form

<form method="post" action="process.php">

            <label class="fieldLabel">Your email:</label><label class="errorLabel"><?php echo $form->error("email"); ?></label> 
            <input type="text" name="email" maxlength="100" class="email" value="<?php echo $form->value("email"); ?>" />

            <label class="fieldLabel">Your enquiry:</label><label class="errorLabel"><?php echo $form->error("body"); ?></label>
            <textarea name="body" class="enquiry"><?php echo $form->value("body"); ?></textarea>    

            <input type="submit" name="enquiry" class="button" value="Send Message"/>

        </form>

On the same page, I have this if statement

if(isset($_SESSION['enq'])){
       if($_SESSION['enq']){
           echo "<h2>Your message has successfully been sent to Alan Slough.</h2>";
       }
       else{
           echo"<h2>Oops, something went wrong. Please try again.</h2>";
       }
       unset($_SESSION['enq']);
    }

Now the process.php file the form directs to

class Process{
//class constructor
function Process(){
    if(isset($_POST['enquiry'])){
        $this->enquiry();
    }
}

function enquiry(){
    global $session, $form;
    //Registration attempt
    $retval = $session->enquiry($_POST['email'], $_POST['body']);

    //Successful 
    if($retval == 0){
        $_SESSION['enq'] = true;
        header("Location: contact-us.php");
    }
    //Error found with form
    else if($retval == 1){
        $_SESSION['value_array'] = $_POST;
        $_SESSION['error_array'] = $form->getErrorArray();
        header("Location: contact-us.php");
    }
    //Failed
    else if($retval == 2){
        $_SESSION['enq'] = false;
        header("Location: contact-us.php");
    }
} 

};

And now the session page where everything happens

//enquiry being made
function enquiry($email, $body){
    global $form;

    //check email entered
    $field = "email"; 
    if(!$email || strlen($email = trim($email)) == 0){
        $form->setError($field, "* Not entered");
    }

    //check body(s) entered
    $field = "body"; 
    if(!$body || strlen($body = trim($body)) == 0){
        $form->setError($field, "* Not entered");
    }

    //if errors exist, send them back to the user
    if($form->num_errors > 0){
        return 1; //errors with form
    }
    else if($form->num_errors == 0){
        $this->customerEnquiry($email, $body);
            return 0; //successful
    }
    else{
        return 2; //failed
    }
}

//send the enquiry to the account email
function customerEnquiry($email, $body){

    $from = "From: ".$email." <".$email.">";
    $to = "random@email.com";
    $subject = "Website enquiry from ".$email."";
    return mail($to,$subject,$body,$from);
}

Ok my problem is that the errors aren’t coming back if I don’t fill in the form. Also, the success text isn’t being displayed if I don’t?

Anyone see a problem with how this flows?
Hoping I have just missed something simple!

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:33:45+00:00Added an answer on May 24, 2026 at 5:33 am

    I noticed this bit of code.

    if(isset($_SESSION['enq'])){ // <---This...
       if($_SESSION['enq']){ // <---And This
           echo "<h2>Your message has successfully been sent to Alan Slough.</h2>";
       }
       else{
           echo"<h2>Oops, something went wrong. Please try again.</h2>";
       }
       unset($_SESSION['enq']);
    }
    

    If $_SESSION[‘enq’] is not set, then the IF statement inside that will never execute, meaning you will see neither the success nor failure message.

    Also, are you starting the session anywhere on the page? If you never start a session, then $_SESSION[‘enq’] will never be set.

    http://www.php.net/manual/en/function.session-start.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple PHP script that sends a message to a specified email
I have written some simple code, to send en auto generated email, using the
I have a website with a contact form. User submits name, email and message
I have a simple little email app that allows a user to pick certain
I have a user system set up in a 'users' table, and I have
I have a system whereby a user can view categories that they've subscribed to
I have a system that stores vectors and allows a user to find the
I currently have built a system that checks user IP, browser, and a random-string
On a System.Web.UI.Page.ViewPage I have access to the current User ( System.Security.Principal.IPrincipal ) but
I am going to be making a small user system but I have questions.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.