I have created a contact form for a website but it doesn't seem to email when I submit a form.

here is the form code

<form action="email_contact.php" method="post"> 
            <input type="text" name="name" value="" placeholder="Your Name"/><br>
            <input type="text" name="email" value="" placeholder="Your Email"/> <br>
            <textarea name="projectDetails" placeholder="Your Project Details."></textarea>
            <br>
            <button> Submit! </button>
          </form>

and here is the php code that it links to when submitted

<?php
$to="backstback@hotmail.com";
$subject = "Competition Information";
$message = "Netball:     " . $_POST['name'] . "\r\n" .
"Email:            " . $_POST['email'] . "\r\n" .
"Info              " . $_POST['projectDetails'] ."\r\n" .
$from = $_POST['email'];
$headers = "From: $from" . "\r\n";
mail($to,$subject,$message,$headers);
?>

I'm Completely stumped on this. Any help is appreciated.

Recommended Answers

All 16 Replies

Member Avatar for diafol

Are you on a local machine or remote server?

im on a remote server

just a small update; the Form is on my page called contact.html and the php is on a page called email_contact.php

I've always had trouble dealing with contact forms, I usually use PHPMailer class to send my mail, you might want to check it out http://phpmailer.worxware.com/

If you don't like using someone else's code then make sure you have the sendmail binary installed.

http://www.cyberciti.biz/tips/howto-setup-sendmail-php-mail-chrooted-apache-lighttpd.html

might help

if you're with a hosting company, they should have most of those stuff configured. All I can say from experience is that if you're hosting with goDaddy, you're screwed.

I was hoping i wouldn't have to install anything and could do it by generic php code

so i got it working with your help the only problem now is that is sends to emails, 1 with nothing contained in it and the 2nd has all the information.

any one have any ideas why?

yeah, I didn't want to use PHPmailer at first but this did save me a lot of headache.

So the first mail sent is empty and the second mail has all the subject, from, to, message etc ?

It could be the way your contact form handles the sent message, it's a little hard to tell with out looking at the source. make sure you check out all the properties and methods that can be used and also check out the tutorials they have.

Member Avatar for diafol

How about posting your new code here? This file shows nothing relevant.

hmm, when I click on the link, it goes straight to the

Thank You

Thank you for your email, we have received it and will get back to you as soon as possible.

page

Maybe the message gets sent as soon as the page loads? How do you handle the form submission?

the email is sent when that page loads, with the script but still sends two

<?php
$to="contact@rmelnikas.host22.com";
$subject = "Competition Information";
$message = "Netball:     " . $_POST['name'] . "\r\n" .
"Email:            " . $_POST['email'] . "\r\n" .
"Info              " . $_POST['projectDetails'] ."\r\n";
$from = $_POST['email'];
$headers = "From: $from" . "\r\n";
mail($to,$subject,$message,$from,$headers);
?>

im not sure with this - $headers = "From: $from" . "\r\n";

i think it should be - $headers = "From:".$from."\r\n";
variable could not be include in "" or '' coz it will read as string

and create some funtion to refuine youre message e.g stripslashes.. its important if theres a special char in message..

sorry for my bad english...

and any way qazplm114477 was right.. i think you forgot to add if(isset($_POST)){
youre script
}

ok i will try that

I have figured it out, thanks for the help the code i used was this if anyone needs any help on the same issue

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail( "someone@example.com", "Subject: $subject",
  $message, "From: $email" );
  echo "Thank you for using our mail form";
  }

cool, if we helped resolved your issue, please mark this thread as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.