Page 1 of 1

PHP script problem...

Posted: Tue Jun 02, 2009 3:42 am
by snehachoudhary
Hi to all,

I know I am going to ask a silly question. But there is no way out. I have developed a HTML website. Now It has a "contact us" form. Now the client want that the details which the user will enter in the form should go to his email address.

I searched a lot and got the answer it is done by using php script. Then I made a php script. But I am unable to send the email. I am doing like this:

PHP Script:

Code: Select all

 
<!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">
 
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
 
<body>
<?php
  $firstname = $_POST['firstname'] ;
  $lastname = $_POST['lastname'] ;
  $company = $_POST['company'] ;
  $phoneno = $_POST['phoneno'] ;
  $mobileno = $_POST['mobileno'] ;
  $email = $_POST['email'] ;
  $city = $_POST['city'] ;
  $country = $_POST['country'] ;
  $message = $_POST['message'] ;
  $email_to = "rohanrajpoot@hotmail.com";
  $email_subject = "contact details of the User";
 
  
  $format = <<<EOF
<html>
<body bgcolor="#F0EFE3">
 
<h3>Message from your website:</h3> <br />
First Name: $firstname<br />
Last Name: $email<br/>
Company: $company<br/>
Phone No:$phoneno<br/>
Mobile No:$mobileno<br/>
E-Mail:$email<br/>
City:$city<br/>
Country:$country<br/>
Message:$message<br/>
 
</body>
</html>
EOF;
 
  mail( $email_to, $email_subject,$format,$email );
 
?>
 
</body>
 
</html>
 
 
In the Html form I am using these lines:

Code: Select all

 
     <form id="form1" name="form1" action="sendmail.php" method="post" enctype="text/plain"  >
 
 
Please assist me where I am lacking. Waiting for your response.

cheers
sneha

Re: PHP script problem...

Posted: Tue Jun 02, 2009 6:48 am
by susrisha
1. I beleive this post goes into the php code section.
@moderator.. please shift to php code section.
2. What is the output that you are getting?
3. Please turn the error reporting on. (either in php.ini file or add this line..)

Code: Select all

 
ini_set('display_errors', 1);
 
at the start of the php tag.
4. Let us know if you come up with any errors..

Re: PHP script problem...

Posted: Tue Jun 02, 2009 9:05 am
by mikemike
You problem is probably related to the mail() function.

The fourth argument should be mail headers. You've just given it a string email address. If you want it to look like it comes from that email then you should use the 'From:' header. Also, it looks like you're using a HTML email format, but you're sending in plain text, again this is where headers come in. Try the following:

Code: Select all

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$firstname.' '.$lastname.' <'.$email.'>'."\n\n";
 
mail( $email_to, $email_subject, $format, $headers );
 

Re: PHP script problem...

Posted: Tue Jun 02, 2009 10:49 am
by Benjamin
Forum Rules 1-1.1-1 wrote: Select the correct board for your query. Take some time to read the guidelines in the sticky topic.
Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.

You may also want to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url]
[*][url=http://php.net/]PHP Manual[/url]
[*][url=http://www.google.com/search?client=opera&rls=en&q=php+tutorials&sourceid=opera&ie=utf-8&oe=utf-8]PHP Tutorials[/url][/list]

 :arrow: Moved to PHP - Code