Question regarding to sendmail.php

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
stevesujk32
Forum Newbie
Posts: 2
Joined: Tue Aug 30, 2011 7:29 am

Question regarding to sendmail.php

Post by stevesujk32 »

Hello all,

I am a beginner to php.

I need some help with my sendmail.php file.


Following is code of the contact form

Code: Select all

<form id="contact1" name="contact1" method="post" action="../sendmail.php">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
        	<td width="20%" height="30" align="left" valign="middle"><span style=" font-family:Verdana, Geneva, sans-serif; font-size:11px; color:#333333;">Name:</span></td>
        	<td width="80%" height="30" align="center" valign="middle"><input type="text" name="name" id="name" style="width:90%; font-family:Verdana, Geneva, sans-serif;" /></td>
      	</tr>
     	<tr>
        	<td width="20%" height="30" align="left" valign="middle"><span style=" font-family:Verdana, Geneva, sans-serif; font-size:11px; color:#333333;">Number:</span></td>
        	<td width="80%" height="30" align="center" valign="middle"><input type="text" name="number" id="number" style="width:90%; font-family:Verdana, Geneva, sans-serif;" /></td>
      	</tr>
      	<tr>
        	<td width="20%" height="30" align="left" valign="middle"><span style=" font-family:Verdana, Geneva, sans-serif; font-size:11px; color:#333333;">Email:</span></td>
        	<td width="80%" height="30" align="center" valign="middle"><input type="text" name="email" id="email" style="width:90%; font-family:Verdana, Geneva, sans-serif;" /></td>
      	</tr>
      	<tr>
        	<td width="20%" height="30" align="left" valign="middle"><span style=" font-family:Verdana, Geneva, sans-serif; font-size:11px; color:#333333;">Subject:</span></td>
        	<td width="80%" height="30" align="center" valign="middle">
            	<select name="select" id="select" style="width:90%; font-family:Verdana, Geneva, sans-serif;">
        			<option value="GeneralEnquiry">General Enquiry</option>
        			<option value="Business Enquiry">Business Enquiry</option>
        			<option value="Other Enquiry">Other Enquiry</option>
      		     </select>
             </td>
      	</tr>
     	<tr>
        	<td height="30" align="left" valign="middle">&nbsp;</td>
        	<td height="30" align="right" valign="middle" style="padding-right:15px;">
            	<input name="submit" type="submit" id="submit" style="font-family:Verdana, Geneva, sans-serif;" onclick="MM_validateForm('name','','R','number','','R','email','','R');return document.MM_returnValue" value="Submit"/>
           	 </td>
     	</tr>
   </table>
</form>
sendmail.php file

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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

	<?php
	$to = "stevesujk32@msn.com";
	$subject = "Client Contact";
	$name = $_REQUEST['name'] ;
  	$number = $_REQUEST['number'] ;
  	$email = $_REQUEST['email'] ;
  	$select = $_REQUEST['select'] ;
	$from = $email;
	$headers = "From:" . $email;
	mail($to,$subject,$message,$headers);
	echo "Mail Sent.";
	?>
</body>
</html>
Also, does anyone know how to do redirection. I have try the code "header( 'Location: http://www.google.com' )" but it returns with error.

Can any please help me on this.

Thank you all.

Sincerely,

Steve
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: Question regarding to sendmail.php

Post by phphelpme »

What is it you are having problems with?

What error messages are you getting when you fill in the form and submit?

What error messages are you getting when you try to use the header() function

Best wishes
stevesujk32
Forum Newbie
Posts: 2
Joined: Tue Aug 30, 2011 7:29 am

Re: Question regarding to sendmail.php

Post by stevesujk32 »

Thank you for the reply.

The main issue is that I can receive an email that sent from the form, but with no content in it.

About the Redirection error, it is an different sendmail.php file.

I am not able to show you the error message now, but basically, it just tells you which line of the code in the .php file is having error.

And the line of error is the redirection code "header( 'Location: http://www.google.com' )" .

Hope it is enough information.

Thank you

Steve
User avatar
phazorRise
Forum Contributor
Posts: 134
Joined: Mon Dec 27, 2010 7:58 am

Re: Question regarding to sendmail.php

Post by phazorRise »

your code and some questions added-

Code: Select all

<?php
   $to = "stevesujk32@msn.com";
   $subject = "Client Contact";
   $name = $_REQUEST['name'] ;
     $number = $_REQUEST['number'] ;
     $email = $_REQUEST['email'] ;
     $select = $_REQUEST['select'] ; //what is this ?
   $from = $email;
   $headers = "From:" . $email;
   mail($to,$subject,$message,$headers);  //where's $message being set ?
   echo "Mail Sent.";
   ?>
this code is not good to use at all. reasons -
-> User input not cleaned.
-> Headers not neatly set.
-> $_REQUEST[] used instead of $_POST.
-> $message variable not set ( this is reason when you're receiving email with no body at all. )
-> Errors not displayed when mail not send.

and for your second error about redirect, show that code and exact error message.
Post Reply