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

  • SEARCH
  • Home
  • 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 8450711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:02:46+00:00 2026-06-10T11:02:46+00:00

I have a problem with the form I’m trying to create. Basically, it does

  • 0

I have a problem with the form I’m trying to create. Basically, it does not allow me to send the email to the recipient, even though the PHP code is correct. Could it be the problem with TRIM PHP code?

<?php
    if ($_POST['submit']) {
        if (empty($_Post['name'])  || 
            empty($_POST['email']) || 
            empty($_POST['comments'])) {

            $error = true;
        } 
        else {

            $to = "linardsberzins@gmail.com";

            $name = trim($_POST['name']);
            $email = trim($_POST['email']);
            $comments = trim($_POST['comments']);

            $subject = "Contact Form";

            $messages =  "Name: $name \r\n Email: $email \r\n Comments: $comments";
            $headers = "From:" . $name;
            $mailsent = mail($to, $subject, $message, $headers);

            if ($mailsent) {
                $sent = true;
            }
        }
    }
?>

My HTML is:

<?php if($error == true){ ?>

    <p class="error">Text</p>

<?php } if($sent == true) { ?>

    <p class="sent">Text</p>

<?php } ?>

<div id="form">
    <form name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <fieldset>
            <h4>Contact Me!</h4>
            <label for="name">Name:</label>
                <input type="text" name="name" id="name"/>
                <label for="email"/>Email:</label>
                <input type="text" name="email" id="email"/>
                <label for="comments" id="comments">Comments:</label>
                <textarea name="comments" id=""></textarea>
                <fieldset>
                    <input class="btn" type="submit" name="submit"   class="submit" value="Send email"/>
                    <input class="btn" type="reset" value="Reset"/>
                </fieldset>
        </fieldset>
    </form>
  • 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-06-10T11:02:48+00:00Added an answer on June 10, 2026 at 11:02 am

    Try this (I had to fix a number of things):

    <?php
        $error = false;
        $sent = false;
    
        if(isset($_POST['submit'])) {
            if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments'])) {
                $error = true;
            }
            else {
                $to = "linardsberzins@gmail.com";
    
                $name = trim($_POST['name']);
                $email = trim($_POST['email']);
                $comments = trim($_POST['comments']);
    
                $subject = "Contact Form";
    
                $message =  "Name: $name \r\n Email: $email \r\n Comments: $comments";
                $headers = "From:" . $name;
                $mailsent = mail($to, $subject, $message, $headers);
    
                if($mailsent) {
                    $sent = true;
                }
            }
        }
    ?>
    
    <?php if($error == true){ ?>
    <p class="error">Text</p>
    <?php } if($sent == true) { ?>
    <p class="sent">Text</p>
    <?php } ?>
    <div id="form">
        <form name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <fieldset>
                <h4>Contact Me!</h4>
                <label for="name">Name:</label>
                    <input type="text" name="name" id="name"/>
                    <label for="email"/>Email:</label>
                    <input type="text" name="email" id="email"/>
                    <label for="comments" id="comments">Comments:</label>
                    <textarea name="comments" id=""></textarea>
                    <fieldset>
                    <input class="btn" type="submit" name="submit"  class="submit" value="Send email"/>
                    <input class="btn" type="reset" value="Reset"/>
                    </fieldset>
            </fieldset>
        </form>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem SIMILAR to preventing form data reposting, but not quite the same
I have a problem with a form, I can't send it. If I put
i have problem in javascript email validation, I wrote code something like, //emp.php <form
I close form with form.Dispose() but i have problem that all opened MessageBoxes does
Well, i have a problem validating a form with jQuery. I'm Not using any
I have problem with a long form in iOS. The form itself is done
I have problem with show or hide form in Window Form Application. I start
I have a problem with dojox.form.Uploader. I want to use it to attach files
I have problem with TinyMCE editor. I have form with few text fields and
I have problem in declaring the intents on my app. I have a form

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.