-1

I am having trouble using the mail() function in php. I am currently learning about it at treehouse but no matter what i do, i just couldnt seem to send the email.

Previously, there were a lot of codes used to avoid spammers and bots. I tried to dumb it down to the simplest and it still wouldn't work, meaning that i still can't use it to send an email despite uploading the file to a free web host that supports php just for testing purposes using filezilla.

May I know what did i do wrong?

The webhost name is www.000webhost.com

Below is the code:

<?php

$to="theteam@theopencircles.com";
$subject="this is from your mother";
$message=$_POST["message"];

if($_POST){
    mail($to,$subject,$message);
}

?>

<!DOCTYPE html>
<html>
    <body>
        <form method="post" action="">
        <input type = "text" name="message" id="message"/>
        <input type = "submit" name = "submit" id="submit" value="submit"/>
        </form>
    </body>
</html>
chiwangc
  • 3,566
  • 16
  • 26
  • 32
G.F.Yu
  • 95
  • 1
  • 1
  • 9
  • There's an invalid quote at the end of the line containing the `mail()` function. – KIKO Software May 26 '15 at 07:17
  • Where is the action for your HTML form? As you appear to be POSTing to the same script, insert the name of the script. – foxbeefly May 26 '15 at 07:19
  • I don't think your code is broken. PHP `mail()` might be limited feature of free 000webhost account http://www.000webhost.com/forum/web-programming/22787-php-mail-000webhost-free-hosting.html – Nikko May 26 '15 at 07:43

3 Answers3

1
<?php
if($_POST["submit"] == 'submit')
{    
$to="theteam@theopencircles.com"; 
$subject="this is from your mother"; 
$headers="sender email-id";
$message=$_POST["message"];
mail($to,$subject,$message,$headers);
}    
?>
Hitesh Vala Ahir
  • 773
  • 2
  • 13
  • 27
0

same time it problem from server side configuration. Please config your php.ini or contract to server admin

0

you can switch to php mailer https://github.com/PHPMailer/PHPMailer phpmailer has all email related readymate functions

Manoj
  • 118
  • 12