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 7561747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:14:11+00:00 2026-05-30T13:14:11+00:00

I can get the PHP mailform to work correctly. The problem is I would

  • 0

I can get the PHP mailform to work correctly. The problem is I would like the submit button upon validation to not refresh the entire page but just the content div layer. I have researched various solutions however I am fairly new to PHP so I may be entering the code incorrectly. The working page can be found at http://www.kaimeramedia.com/derek/Website and then by clicking on the contact link. The actual contact page code is:

 <form method="post" id="captcha_form" name="form1" action="mailform.php">
                        <br />
                        <table width="100%" border="0"> 
                          <tr><td rowspan="4" width="125">
 </td> 
                            <td>
 <div id="Imprint3">Name:</div></td>
                                <td width="15"> 
 </td><td><div id="Imprint3">All fields are required.</div></td> 
                          <tr>
                              <td width="150">
 <input type="text" id="name" name="name" maxlength="30" value="name" onfocus="if
 (this.value==this.defaultValue) this.value='';"/></td>
                          <td rowspan="5" colspan="2">
                                <table>
                                  <tr><td width="10"></td><td>
 <div id="Imprint3">Message:</div></td></tr>
                                <tr><td width="10">
 </td>
                                <td width="200"><textarea name="message" id="message" 
 rows="6" cols="25" value="Enter your message" onfocus="if
 (this.value==this.defaultValue) this.value='';"/><?php echo "</tex" . "tarea>"; ?>                                   
 </td> 
                            </tr> 
                            <tr> 

 <td align="center" colspan="2"> 

 <input name="submit" type="submit" value="Submit" />

 <input type="button" name="reset_form" value="Reset" onclick="this.form.reset();">
 </td></tr></table>                                 
 </td> 
                            </tr> 
                            <tr> 

 <td valign="top"><div id="Imprint3">Email:</div></td> </tr>
                                <td valign="top">  
 <input type="text" id="email" name="email" maxlength="100" value="you@email.com" 
 onfocus="if(this.value==this.defaultValue) this.value='';"/></td>                              
                            </tr> <tr> 
                              <td width="15"></td>
 <td align="center"> <div style="padding-bottom: 1em;">
  <img src="captcha.php" /> <br />
<input type="text" name="userpass" value="input the above text here" onfocus="if
 (this.value==this.defaultValue) this.value='';"></div></td></tr></table></form>

and the mailform.php file is as follows:

 <?PHP
 session_start();
 try{
$check = new check();
if(!isset($_REQUEST['email']))
    throw new exception('You did not enter an email address.');

if(!isset($_REQUEST['message']))
    throw new exception('You did not enter a message.');

if(!isset($_REQUEST['name']))
    throw new exception('You did not enter a name');

$sender = $_REQUEST['email'];
$message = $_REQUEST['message'];
$name = $_REQUEST['name'];
$recipient = 'text@text.com';

$subject = 'Regarding Your Portfolio';

if($check->captcha('userpass') == FALSE)
    throw new exception('Your captcha is incorrect.');

if($check->spam($sender) == FALSE)
    throw new exception('Your email field contains spam.');

if($check->spam($name) == FALSE)
    throw new exception('Your name field contains spam.');

if($check->length($sender, 10) == FALSE)
    throw new exception('Your email field does not satisfy the minimum character    
count.');

if($check->length($message, 8) == FALSE)
    throw new exception('Your message field does not satisfy the minimum character 
count.');

if($check->length($name, 3) == FALSE)
    throw new exception('Your name field does not satisfy the minimum character count.');

mail($recipient, $subject, $message, "From: $name <$sender>" );
include'thankyou.php';

}catch (Exception $E){
die($E->getMessage());

}





class check{

function captcha($field){
    if(isset($_REQUEST[$field])==FALSE){ return false; }
    if($_SESSION['pass'] != $_REQUEST[$field]){ return false; }
    return true;
}

function email($email){
    if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ return false;}
    return true;
}

function spam($field){
    if(eregi("to:",$field) || eregi("cc:",$field) || eregi("\r",$field) || 
eregi("\n",$field) || eregi("%0A",$field)){ return false; }
    return true;
}

function length($field, $min){
    if(strlen($field) < $min){ return false; }
    return true;
}
}
?>

I have replaced my receiving email to text@text.com on this page, but on my site it is my actual email. Another user helped me a lot with getting this script functioning correctly, but I was wondering if it is possible to get the thankyou.php to refresh into the current div layer and not refresh the entire page. the line that I want to edit I believe is the: include 'thankyou.php'; Any help would be appreciated.

  • 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-30T13:14:13+00:00Added an answer on May 30, 2026 at 1:14 pm

    This is not possible with php.
    You will have to use JavaScript to realize this.

    You would be able to send the email without refreshing the page and to load a file in a div.

    With e.g. jQuery and the $.ajax function it would look something like this:

    var msg; // defines variable "msg"
    
    $('#button_ID').click(function(e){
    
    e.preventDefault(); // this prevents the page from reloading (or default behavior, so the form submit)
    
    msg = $('#input_field_ID').val(); // gets the value of the input field and saves it in variable "msg"
    
    $.ajax({
        type: 'POST',
        url: '/sendmail.php',
        data: {message : msg}, // posts variable "msg" as "message"
        cache: false,
        success: function(data) {
            $("#yourdivID").load('/thankyou.php'); // loads a file in a div
        },
        error: function(xhr, ajaxOptions, thrownError){
            alert('there was an error');
        }
    });
    
    });
    

    In this example you would be able to get the message in sendmail.php with $_POST["message"]

    Or use $.post and serialize your entire form:

    $.post("/sendmail.php", $("#formID").serialize());
    

    Just that you can see how to handle something like this.

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

Sidebar

Related Questions

What kinds of information can PHP get about users? I would like to make
How can I get php to not use 1.297503E+17 on large int but 129750300000000000
How can I get a PHP function go to a specific website when it
In php i can get today date/day by using : $today = date('D, Y-m-d');
There's a function in PHP where you can get a list of the user
How can I get the name of a file in in PHP? What I
How can i get all the users from the LDAP using PHP. function getUsers()
How can I get a value from a preprocess function to template.php, in a
using Fast CGI I can't get it to read the php.ini file. See my
In PHP, how can I get the number of seconds until the end of

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.