php mail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
harinibn
Forum Newbie
Posts: 1
Joined: Sun Feb 15, 2009 12:05 pm

php mail

Post by harinibn »

iam trying to send the infrmation from a form to email . I used the following code. but i is not working. could some ne help me with this. I appreciate your help.

Code: Select all

 
<?php 
$to = "you@yoursite.com"; 
$subject = "Contact Us"; 
$email = $_REQUEST['email'] ; 
$message = $_REQUEST['message'] ; 
$headers = "From: $email"; 
$sent = mail($to, $subject, $message, $headers) ; 
if($sent) 
{print "Your mail was sent successfully"; }
else 
{print "We encountered an error sending your mail"; }
?>
 
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php mail

Post by jackpf »

An error message or something of the sort would be useful, but I guess this isn't working because mail() doesn't return a value if it fails.
If you do something like this:

Code: Select all

 
<?php
if(!isset($_REQUEST['message']))
{
die('Error. Please revise.');
}
?>
 
for each variable you're getting from the form, then there's a very high chance that mail() will send.
Hope that helped...
Jack.
Post Reply