PHP script problem...

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
snehachoudhary
Forum Newbie
Posts: 1
Joined: Tue Jun 02, 2009 3:26 am

PHP script problem...

Post 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
Last edited by Benjamin on Tue Jun 02, 2009 10:47 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: PHP script problem...

Post 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..
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: PHP script problem...

Post 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 );
 
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP script problem...

Post 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
Post Reply