0

I am having a bit trouble getting the PHP script to work. I am making a very basic form just collecting name and email

<form action"email.php" method="POST" id="signup-form">
                    <p><input type="text" id="name" name="name" placeholder="name" /></p>
                    <p><input type="email" id="email" name="email" placeholder="email address" /></p>
                    <p class="form-note"><em>* we will only email you when our store is up</em></p>
                    <p><input type="submit" value="Get Notified" /></p>
                </form>

My PHP script is

<?php
    $error = false;
    $sent = false;

    if(isset($_POST['submit'])) {
        if(empty($_POST['name']) || empty($_POST['email'])) {
            $error = true;
        } 
        else {

            $to = "[email protected]";

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

            $subject = "New Subscriber";

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

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

I'm using a Linux hosting company, net registry. I tried to get the PHP errors turned on, but couldn't see how in my cpanel. The mail is not sent, but I have no way of seeing the error preventing it.

3
  • 2
    Doesn't work how? Do you get an error? The mail doesn't get sent? What happens? We don't live inside your head and can't know what you're thinking. Commented Nov 28, 2013 at 12:46
  • can you send an email from your severs mail server? are you running xampp? or wamp? if so email isn't by default configured Commented Nov 28, 2013 at 12:48
  • I updated the post running on a linux hosting server. @AmalMurali Commented Nov 28, 2013 at 12:53

2 Answers 2

3

You have an error in your html. Try:

<form action="email.php"
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, what a silly mistake. Now I notice it seems the form is sending but goes to a blank page email.php and nothing still seems to be sent.
1

Change your HTML to this and try

<form action="email.php" method="POST" id="signup-form">
                    <p><input type="text" id="name" name="name" placeholder="name" /></p>
                    <p><input type="email" id="email" name="email" placeholder="email address" /></p>
                    <p class="form-note"><em>* we will only email you when our store is up</em></p>
                    <p><input type="submit" value="Get Notified" /></p>
                </form>

1 Comment

thanks I realized I forgot the equal sign, now when submitting the form, it just goes to the email.php page and nothing is sent to my email

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.