954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php form not working

i have created a simple form (well with the help of a book ).
i am able to process the data and display it . But i amnot able to send the same message to my mail ID.
i am using WAMP server. i am running the script from my system .

The normal form code (report.html)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Aliens Abducted Me - Report an Abduction</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
  <h2>Aliens Abducted Me - Report an Abduction</h2>

  <p>Share your story of alien abduction:</p>

  <form method="post" action="report.php">

    <label for="firstname">First name:</label>
    <input type="text" id="firstname" name="firstname" />
    
    <label for="lastname">Last name:</label>
    <input type="text" id="lastname" name="lastname" />
    
    <label for="email">What is your email address?</label>
    <input type="text" id="email" name="email" />

    
    <label for="whenithappened">When did it happen?</label>
    <input type="text" id="whenithappened" name="whenithappened" />
    
    <label for="howlong">How long were you gone?</label>
    <input type="text" id="howlong" name="howlong" />
    
    <label for="howmany">How many did you see?</label>
    <input type="text" id="howmany" name="howmany" />
    
    <label for="aliendescription">Describe them:</label>

    <input type="text" id="aliendescription" name="aliendescription" size="32" />
    
    <label for="whattheydid">What did they do to you?</label>
    <input type="text" id="whattheydid" name="whattheydid" size="32" />
    
    <label for="fangspotted">Have you seen my dog Fang?</label>
    Yes <input id="fangspotted" name="fangspotted" type="radio" value="yes" />
    No <input id="fangspotted" name="fangspotted" type="radio" value="no" />
    
     <img src="fang.jpg" width="100" height="175"
      alt="My abducted dog Fang." />

    <label for="other">Anything else you want to add?</label>
    <textarea id="other" name="other"></textarea>
    
    <input type="submit" value="Report Abduction" name="submit" />
  </form>
</body>
</html>


Then the page (report.php)

<html>
<head>
     <title> The aliens abducted me </title>

</head>

<body>
    <h2> The final report </h2>

<?php
$name = $_POST['firstname'].' '.$_POST['lastname'];

$when_it_happened = $_POST['whenithappened'];

$how_long = $_POST['howlong'];

$alien_description = $_POST['aliendescription'];

$fang_spotted = $_POST['fangspotted'];

$email = $_POST['email'];


$to = 'rahul8590@yahoo.com';

$subject = ' this is the subject ';

$msg = "Thanks for aubmitting the form $name". '<br/>' .
       " You were abducted $when_it_happened". '<br/>'.
       "fnag spotted : $fang_spotted ";

mail($to , $subject , $msg, 'from:'.$email);

echo $msg;


?>

the i get this error :

The final report
------------------------------------------------------------------------------
Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for rahul8590@yahoo.com in C:\wamp\www\ch1\report.php on line 32
----------------------------------------------------------------------------------
Thanks for aubmitting the form fdgvdf fdg df
You were abducted df gfd f
fnag spotted : yes

its printing the message which is been filled in the form , but i have no idea why it isnt sending the mail to the my mail id.
i would be glad if u guys can help me out.

rahul8590
Posting Whiz
351 posts since Mar 2009
Reputation Points: 92
Solved Threads: 20
 

wampserver is not equipped with an smtpserver by default. One option would be to use a tool like phpmailer, to send your emails through your gmail/hotmail/provider account.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

mail($to , $subject , $msg, 'from:'.$email);

try to remove 'from:'.$email just put $email only. or put in one variable that statement.

$headers = 'from:'.$email;

mail($to , $subject , $msg, $headers);

I did not run your code but can you try it?

phpbeginners
Posting Whiz in Training
226 posts since Jul 2009
Reputation Points: 12
Solved Threads: 32
 

go for phpmailer

Manuz
Junior Poster
122 posts since Oct 2008
Reputation Points: 12
Solved Threads: 24
 

Using phpmailer is an opinion not a solution.

The first step is to identify the issue.
Take the $headers out of the mail function and test the script again.
Does it work?
If so, your headers need to be correct.

These headers will work for plain text, no attachement. Don't forget to set $fromaddress to the proper address.

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r \n";
$headers .= "From: \"$fromaddress\" <$fromaddress>\r \n";
$headers .= "Reply-To: \"$fromaddress\" <$fromaddress>\r \n";
$headers .= "Date: " . date("r") . "\r\n";
SoN9ne
Light Poster
45 posts since Jul 2009
Reputation Points: 12
Solved Threads: 6
 

"The first step is to identify the issue. "

I agree. mail() still won't work because there comes no smtp server with wampserver.

using phpmailer will allow you to use an other server than localhost, something which mail() does not support.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

well firstly sorry for late reply, i still didnt get few things.
"The first step is to identify the issue. "

well since i am naive in this field , all i can get from the error messgae is that i am not able to send messages, according to all the post put up it comes to the conclusion thatWamp server had no SMTP

1. Is there ne way in which i can config or add ne module in WAMP so that the SMTP is incorporated into it.

Take the $headers out of the mail function and test the script again. Does it work? If so, your headers need to be correct.

These headers will work for plain text, no attachement. Don't forget to set $fromaddress to the proper address. Help with Code Tags php Syntax (Toggle Plain Text)

$headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/plain; charset=iso-8859-1\r \n"; $headers .= "From: \"$fromaddress\" <$fromaddress>\r \n"; $headers .= "Reply-To: \"$fromaddress\" <$fromaddress>\r \n"; $headers .= "Date: " . date("r") . "\r\n";

honestly So9NE , i have no idea what ur talking about , i would be glad if u could be a little more explicit.One option would be to use a tool like phpmailer, to send your emails through your gmail/hotmail/provider account.

i would appreciate if u could enlighten me abt phpmailer.
As a matter of fact is there any other modules (or what ever its called) like these, which can enhance the performance of PHP ...?

rahul8590
Posting Whiz
351 posts since Mar 2009
Reputation Points: 92
Solved Threads: 20
 

I think this is a good start

http://www.110mb.com/forum/howto-send-emails-using-phpmailer-and-gmail-t14144.0.html

A lot of modules are made in PEAR, pear.php.net
It just makes life easier.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You