Re: Need help-Send email
| From: | nagendra prasad | Date: | Sat, 12 Sep 2009 10:40:38 +0000 |
| Subject: | Re: Need help-Send email | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-46487@lists.php.net to get a copy of this message | ||
Hi all,
Below is the code that I have coded after replies from all of you. But
before that I want to thank all of you for your help. I have coded the email
code but still it is giving me an error. Please help me.
<?php
//sending email script
$to = "example@gmail.com";
$subject = "Email from admin";
if ($_POST['submit'])
{
//get data from form
$name = $_POST['name'];
$message = $_POST['message'];
if ($name&&$message)
{
$namelen = 20;
$messagelen = 300;
if (strlen($name)<=$namelen && strlen($message)<=$messagelen)
{
//everything is ok
ini_set("SMTP", "smtp.gmail.com");
$to = "example@gmail.com";
$subject = "Email from admin";
$header = "from: example@gmail.com";
$body = "Email from $name \n\n $message";
mail($to,$subject,$body,$header);
die();
}
else
die ("Max length of name is $namelen, and max length for message is 300");
}
else
die("you must enter a name");
}
?>
<html>
<form action='sendemail.php' method='POST'>
Name: <input type='text' name='name'
maxlenght='20'><br>
Message: <br><textarea name='message'></textarea><p>
<input type='submit' name='submit' value='Send an
email'>
</form>
</html>
--------------------------------------------------------------------------------------
Also I have simplified the code by just using the email() function but the
problem is its sending the mail in the SPAM. The code is below :
<?php
$to = "example@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "example@gmail.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>