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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:22:12+00:00 2026-05-24T10:22:12+00:00

I have a PHP email form and the user enters their email and it

  • 0

I have a PHP email form and the user enters their email and it sends them the link to the file they uploaded. How would I submit that form with AJAX?

Right now, I have it where they click on a link to go to the page with the email form on it, and I am passing the $target_path variable in the URL so the link to the uploaded file can be in the email. Here’s the PHP I have on the “Successfully uploaded” page to go to email.php:

<?php echo "<a href='email.php?target_path=".$target_path."'>Click here</a> to get the link sent to your email." ?>

Here’s the source of email.php:

<html>
<head>
<title>Upload File</title>
<style type="text/css">
body {
font-family:arial,sans-serif;
}
.error {
color:red;
}
</style>
</head>
<body>
<?php
function spamcheck($field)
  {
  //filter_var() sanitizes the e-mail
  //address using FILTER_SANITIZE_EMAIL
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);

  //filter_var() validates the e-mail
  //address using FILTER_VALIDATE_EMAIL
  if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }

if (isset($_REQUEST['email']))
  {//if "email" is filled out, proceed

  //check if the email address is invalid
  $mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==FALSE)
    {
    echo "Invalid email, please try again.";
    }
  else
    {//send email
    $to = $_REQUEST['email'] ;
    $subject = "Your file has been uploaded to our site and here's a link to it" ;
    $message = "
Hello,

Your file has been uploaded to our site. Here is a link to it for future reference, keep this email if you want to remember the link to your file: http://www.example.com/upload/".$_REQUEST['target_path']."

Thank you.";

    mail($to,$subject,$message, "From: noreply@example.com" );
    echo "Email has been sent. Please check your inbox and/or spam folder.";
    }
  }
else
  {//if "email" is not filled out, display the form
  echo "<form method='post' action=''>
  Email: <input name='email' type='text' /><br /><br />
  <input type='submit' />
  </form>";
  }
?>
</body>
</html>

As you can see, when they click the link to go to email.php on the “Successfully Uploaded File” page (upload.php) it passes the $target_path variable so it will be able to send a link to the uploaded file.

I would like to put the email form right on upload.php (the page where the file upload form gets submitted to) and then submit that email form with jQuery AJAX. I just don’t know how to make that work. I’ll also need that variable to still be passed, but I don’t think it would be in the URL, it would probably be in somewhere else in the AJAX code.

Any help is greatly appreciated.

Thanks,
Nathan

  • 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-24T10:22:13+00:00Added an answer on May 24, 2026 at 10:22 am

    Following is the JS bit of code

    $(document).ready(function(){
    
        $('#emailbtn').click(function(){
                //This is short form of php echo
            var target_path = <?php=$target_path?> 
    
                //Get eMail from input
                var email = $('#email').val(); 
    
                //Send form to email.php using GET method
            $.ajax(
            {
                type: "GET",
                url: "email.php",
                data: ({"target_path" :  target_path, "email" : email}),
                success: function(message)
                {   
                    $("#btnspan").empty().append(message);
                }
            });         
        });
    });
    

    This is HTML bit of code

    <span id="btnspan">Your eMail: <input type="text" name="email" id="email" /> <button id="emailbtn" class="button">eMail me the link</button></span>
    

    Seems your email.php return valid messages, so what will happen when you click on the button is that content provided by your php will replace the form content! Page does NOT refresh.

    One thing I would suggest you change is the GET method, change it to POST! For php I assume you know it’s $_POST[varname] to retrieve the value and for the JS, just change AJAX type to POST.

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

Sidebar

Related Questions

i have a PHP contact form that submits data, and an email...: <?php $dbh=mysql_connect
I have a PHP application that sends email using the pear Mail function. Unfortunately
I have a page called send.email.php which sends an email - pretty simple stuff
I have a page called send.email.php which sends an email - pretty simple stuff
I have a simple php script on my domain that sends me an email:
I'm programming in PHP and would like to create web pages which have email
I have Ajax file in which code has written to accept values form user
I have a simple email form: <form method=post action=process-form.php id=emailForm name=emailForm target=_self> <h4>Sign up
I have a form which collects user info including name, location, url, email address
i have a form where user can either input email ids like someone@somewhere.com,anyone@anywhere.com OR

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.