Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Form to send Email not working. Is there anything wrong in the code ?

index.html

XML
<html>
<body>

<div id = "container">
<form method  = "post" action = "process.php">

<b><h4>To (Enter an Email address)</h4></b><input type = "email" id = "to" name = "to">

<h4>Enter subject</h4> <textarea name = "subject" rows = "1" cols = "80" > </textarea>

<h4>Enter the message</h4> <textarea name = "message" rows = "17" cols = "100" > </textarea>

<center><input type = "submit" label = "Send"></center>

</form>
</div>

</body>
</html>



process.php

PHP
<?php

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

mail($to, $subject, $message);
echo "Your Email has been sent successfully to" ." ". $to  ;

?>


I'm using LAMP on localhost with postfix SMTP server. I also tried it on a hosting service. Its not working there also. Emails are not going. Anything wrong in the code ?

Pardon if I have done any silly mistake. I learn coding on my own by reading books with no teacher to guide.
Posted
Updated 18-Sep-13 2:20am
v3
Comments
Killzone DeathMan 18-Sep-13 11:52am    
Yeah a silly mistake:

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

Must be:

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

Note: You have "$" when you request the post fields...
"I learn coding on my own by reading books with no teacher to guide." -> I can help you if you want, just add me on skype: miguel.poegel
Allwin456 18-Sep-13 13:04pm    
Thanks a lot for pointing out the mistake. And I'm really glad for your helping hand but unfortunately I don't have a webcam and a microphone to use skype. But I will be happy if I could Email you, Facebook you or simply ask questions here.
Killzone DeathMan 19-Sep-13 4:42am    
No problem! Just add me on skype to send instant messages, there is no need for microphone or webcam!
Regards,
KZ

1 solution

As pointed out by Killzone DeathMan , there was a silly mistake in the code:

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

Must be:

$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900