Email will be dispatched once reCAPTCHA verification is completed

I'm currently facing an issue with sending an email from my website's form via PHP after the reCAPTCHA verification. Whenever I click the submit button, the page refreshes but the email is not being sent. I believe I might be overlooking something simple, as the solutions I've tried so far have been ineffective.

This process is taking place on localhost, and the email sends successfully without the reCAPTCHA code. I apologize for any lack of clarity in my explanation; I am still a beginner in this field.

Below is the HTML snippet:

<form class="contact100-form validate-form" action="#" method="post">
                            <span class="contact100-form-title">
                                Request a demo today!
                            </span>

                            <div class="wrap-input100 validate-input">
                                <input class="input100" type="text" required name="name" placeholder="Full Name">
                                <span class="focus-input100"></span>
                            </div>

                            <div class="wrap-input100 validate-input">
                                <input class="input100" type="text" required name="email" placeholder="E-mail">
                                <span class="focus-input100"></span>
                            </div>
<div class="g-recaptcha" data-sitekey="MY KEY"></div>
</form>

And here is the PHP snippet:

<?php 
          /* [VERIFY CAPTCHA FIRST] */
            $secret = 'SECRET KEY'; // MAKE SURE TO CHANGE THIS KEY!
            $url = "https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=".$_POST['g-recaptcha-response'];
            $verify = json_decode(file_get_contents($url));


          if($verify -> success)
          {
              $to = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="650008040c09250008040c094b060a08">[email protected]</a>"; // set your Email address
              $subject = "SUBJECT NAME";
              $email = $_POST['email];
              $name = $_POST['name'];


              $message = $name .  " wrote the following:" . "\n\n" . $_POST['message'] ."\n\n" . "Contact details: " . $from . "\n\n" . "Company Name: " . $company . "\n\n" . "Company Industry: " . $industry . "\n\n" . "Company Size: " . $size . "\n\n" . "Phone: " . $phone . "\n\n" . "Location: " . $location;

              $headers = "From:" . $from;
              $headers2 = "From:" . $to;
              mail($to,$subject,$message,$headers);
              mail($from,$headers2); // sends a copy of the message to the sender
              // echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
              // Alternatively, use header('Location: thank_you.php'); to redirect to a different page.

          }
?>

Answer №1

Don't forget to include the quotation mark here: $email = $_POST['email];

The correct way is: $email = $_POST['email'];

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transforming PHP Data into the Desired Format

According to the Eventbrite API v3 documentation, it is recommended to submit data in JSON format. I am currently trying to update simple organizer data through an ExtJS grid, but the changes are not being processed. The solution involves MODX and the upd ...

Comparison between Windows Task Scheduler and Node's Cron Scheduler

We are currently developing an application that will manage scheduled SMS sending. Our setup involves a Windows server and we rely on the Task Scheduler provided by Windows for this functionality. However, I am not completely satisfied with this tool. We u ...

How can I assign the user "macuser" to the "_www" group using a command?

How can I add the user "macuser" to the "_www" group on my MacBookAir? I am currently working on a PHP project that creates files and folders with the _www:_www ownership, causing macuser to have limited access. Adding macuser to the _www group should hel ...

Issue with Wordpress Custom Post Type Category Functionality

I've successfully created a custom post type named "Blog" by adding the following code to my theme's functions.php file: function create_posttype() { register_post_type( 'blog', array( 'labels' => array( ...

Using opening and closing curly braces within a PHP foreach loop

I am facing an issue with formatting an array in PHP. The array structure is as follows: Array ( [0] => Array ( [team1_score] => 10 [team2_score] => 5 [round_number] => 1 [teamtitle1] ...

How can I transfer the database from my live server to my localhost using php?

I have a large SQL database operating on a live server. Whenever a bug arises, my usual process is to manually export the database from phpmyadmin (by viewing the output text), dropping the localhost database, importing the output dump, and then importing ...

Arranging items by cost with the help of ajax and php

After successfully implementing product filtering using Ajax and PHP on my real estate website, I'm now facing issues while trying to incorporate the functionality to order the results by price. Despite various attempts, I am unable to add the necessa ...

Investigating the presence of a file within the superior directory with RewriteCond

I am attempting to enhance this .htaccess file in order to redirect all requests to a script when the requested file or directory is non-existent. However, I want to refactor it so that it checks for the existence of the file in the parent folder. Curren ...

When a form is submitted, the PHP file is opened in a new page instead of running the script

I have developed a contact form that needs to be validated through ajax PHP before being sent via PHP email. However, upon clicking submit, the page refreshes and redirects to a new page: mypage.com/form_process.php Additionally, the stylesheet is not l ...

Achieving a doubled value in PHP

My intention is to add two numbers together and have the result displayed as a double. <?php $a=4.0; $b=4; echo $a+$b ?> The expected output should be 8.0, but it currently displays as 8. I am still learning PHP. ...

Is it possible to split a PayPal transaction?

I have a unique request from my client that I would like to share: Imagine if a customer buys something (valued at $100) from my client's online store. My client wants $85 of that amount to go to the item owner, with the remaining $15 kept as commiss ...

Effortlessly inserting and posting data into a database with Laravel, Bootstrap Modal, and Ajax

My issue is that I am unable to retrieve the value of a textarea input in a Bootstrap modal using Input::get(), as it returns null. The submit button and text input in my view: <button type="button" class="btn btn-danger" onclick="customModalSubmitF ...

Is it possible to have a PHP variable embedded within an HTML link tag?

<?php $message = ' <a href="' . $link . '">here</a> '; ?> My goal is to include a clickable link in the $message variable for use in the mail() function. However, despite setting $link with the desired link string, it ...

How can I adjust the format of a timestamp field from the database to adhere to Dutch locale conventions?

I am attempting to convert a timestamp string from the database into a Dutch locale format that resembles: Maandag 2 juli 2013 My approach was as follows: <?php setlocale(LC_ALL, 'nl_NL'); echo strftime("%A %e %B %Y", mktime($vac->gepl ...

Sort the multidimensional array/object by the highest value

Can someone help me order this array/object by maximum value of grossConversions in descending order, with a limit of 10 results? Here is the current output that needs to be sorted: array(19) { [0] => object(stdClass)#355 (8) { ["campaign_name"]=> ...

Identify and handle exceptions from nested PHP scripts

When I run nested scripts using include() within a master script, I am wondering if it is possible to detect and log any errors that may occur during the execution of the nested script, even if they were caught in a try/catch block within the nested script ...

What causes an "Undefined index" error in jQuery when making AJAX requests?

Whenever I make an AJAX request in my main.js file, I encounter the following error message: Undefined index: id in sqlinfo.php on line 13 I am puzzled because I believe that I am populating the request object correctly. What's even more perplexing i ...

The Facebook SDK PHP example code is malfunctioning

I am experiencing issues with the Facebook login feature on this site. Despite downloading the latest PHP SDK and following the example provided at , I am unable to get it to work correctly. While I have managed to make the Javascript component function p ...

Looking for the best method to store user badges on my website. Utilizing PHP to create and manage "Badges"

As I work on integrating "Badges" into my website, I'm contemplating the most effective way to store the data. Each badge will be assigned a unique ID that will be stored in a MySQL database. Every user has their own dedicated row within the MySQL dat ...

Modifying the key values of an associative array

In my code snippet, I am attempting to loop through a JSON array and update the values within it. Here is an overview of what the JSON structure looks like: <?php $json='[{"type":"dropdown","label":"Is the property tenanted ?","req":0,"choices":[{ ...