Log in

View Full Version : can submit a form through e-mail



hansan
07-07-2010, 05:44 PM
Hi all,
I want to know how the submit a form via e-mail. I tried some code but I failed.
this is code that I have tried,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form_info" method="post" action="send_mail.php">
<div>
<table>
<tr>
<td> Your Email</td>
</tr>
<tr>
<td ><input type="text" name="from" value="email"></td>
</tr>

<td>Subject</td>
</tr>
<tr>
<td ><input type="text" name="subject" value="subject"></td>
</tr>
<tr>
<td> Message</td>
</tr>
<tr>
<td><textarea name="message"></textarea></td>
</tr>
<tr>
</table>
<table >
<tr>
<td> <input type="submit" name="Email" value="Email"></td>
</tr>
</table>
<input type="hidden" name="to" value="hadunprera@yahoo.com">
</div>
</form>
</body>
</html>

and send_mail.php,

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<?php

$from = $_POST['from'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = $_POST['to'];

$to="$to";
$headers.= "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; ";
$headers.= "charset=iso-8859-1\r\n";

$headers.= "From: $from";

$subject = "$subject";
$body = "$message";

$send_check=mail($to,$subject,$body,$headers);
if ($send_check!=true) {die();}
?>

<table align="center" >
<tr >
<td>
<div align="center">YOUR MESSAGE HAVE BEEN SENT
</td>
</tr>
</table>
</body>
</html>

then I was upload this code. http://www.haduntest.comli.com/

But it is not working.
When I click one the send button it shows the next page which display "YOUR MESSAGE HAVE BEEN SENT".

But no mail has received to my mail account.

can you tell me what is error with this code ???

prasanthmj
07-08-2010, 04:32 PM
The reason can be the 'from' field See the link below
Why is my PHP script not sending emails (http://www.html-form-guide.com/blog/php-form-email/3/php-script-not-sending-email/)

Also see
PHP Form to email explained (http://www.html-form-guide.com/email-form/php-form-to-email.html)