LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-06-2005, 11:26 PM   #1
czarherr
Member
 
Registered: Sep 2003
Location: Suwon, Korea
Distribution: Slackware 14
Posts: 288

Rep: Reputation: 32
php mail problem


I am a php newb, unfortunately, and I'm trying to write a simple script that will take form information and email it to myself. I fill out the form, but I just get a blank screen when i submit, not even the error message. If i don't enter anything in the fields, I get the appropriate "<name> is required to be entered." errors, but if i enter all required info, the script just doesnt email me and gives me no errors. Here is the script as is, I really hope someone can help.

<html>
<head>
<title>Real Estate</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST'){
$me = $_SERVER['PHP_SELF'];
?>
<h1 align="center">Personal Information</h1>
<center>Thank you for visiting and considering us for your housing needs. Please
simply enter the requested information below and we will get back to you as soon
as possible with the information you requested. Required Information is marked with
an asterisk (*).</center>
<br>
<hr>
<br>
<form name="form1" method="post" action="<?=$me?>">
<table border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td align="right" valign="middle">*First Name:</td>
<td><input name="FirstName" type="text" size="15">
</td>
</tr>
<tr>
<td align="right" valign="middle">*Last Name:</td>
<td><input name="LastName" type="text" size="15">
</td>
</tr>
<tr>
<td align="right" valign="middle">*Telephone Number:</td>
<td><input name="Telephone" type="text" size="15">
</td>
<tr>
<td align="right" valign="middle">Cell Number:</td>
<td><input name="Cell" type="text" size="15"
</td>
<tr>
<td align="right" valign="middle">Work Number:</td>
<td><input name="Work" type="text" size="15"
</td>
<tr>
<td align="right" valign="middle">*Email:</td>
<td><input name="Email" type="text" size="30"
</td>
<tr>
<td align="right" valign="middle">*Approximate Move-In Date:</td>
<td><input name="MoveIn" type="text" size="15"
</td>
<tr>
<td>
<br>
<br>
</td>
</tr>
<tr>
<td align="right" valign="top">*I would like to see:</td>
<td><input name="apartment" type="checkbox"
id="apartment" value="apartment">Apartment
<input name="house" type="checkbox"
id="house" value="house">House<br>
<input name="condo" type="checkbox"
id="condo" value="condo">Condominium
<input name="loft" type="checkbox"
id="loft" value="loft">Loft<br></td>
</tr>
<tr>
<td>
<br>
<br>
</td>
</tr>
<tr>
<td align="right" valign="top">Select all areas of interest:</td>
<td><input name="lakeway" type="checkbox"
id="lakeway" value="lakeway">Lakeway
<input name="barton" type="checkbox"
id="barton" value="barton">Barton Springs
<input name="acc" type="checkbox"
id="acc" value="acc">Austin Community College<br>
<input name="zilker" type="checkbox"
id="zilker" value="zilker">Zilker Park
<input name="pflugerville" type="checkbox"
id="pflugerville" value="pflugerville">Pflugerville
<input name="georgetown" type="checkbox"
id="georgetown" value="georgetown">Georgetown<br>
<input name="roundrock" type="checkbox"
id="roundrock" value="roundrock">Round Rock
<input name="naustin" type="checkbox"
id="naustin" value="naustin">North Austin
<input name="caustin" type="checkbox"
id="caustin" value="caustin">Central Austin<br>
<input name="saustin" type="checkbox"
id="saustin" value="saustin">South Austin
<input name="waustin" type="checkbox"
id="waustin" value="waustin">West Austin
<input name="jollyville" type="checkbox"
id="jollyville" value="jollyville">Jollyville<br>
<input name="jonestown" type="checkbox"
id="jonestown" value="jonestown">Jonestown
<input name="cedarpark" type="checkbox"
id="cedarpark" value="cedarpark">Cedar Park<br>
<input name="otherarea" type="checkbox"
id="otherarea" value="otherarea">Other Austin Area
<input name="unsure" type="checkbox"
id="unsure" value="unsure">Unsure as of yet
</td>
</tr>
<tr>
<td>
<br>
<br>
</td>
</tr>
<tr>
<td align="right" valign="top">Price Range(monthly):</td>
<td><select size="6" name="pricerange">
<option>&lt;$500</option>
<option>$500 to $700</option>
<option>$600 to $1000</option>
<option>$800 to $1200</option>
<option>$1000 to $1500</option>
<option>$1200 to $1750</option>
<option>&gt;$1700</option>
</select></td>
</tr>
<tr>
<td>
<br>
<br>
</td>
</tr>
<tr>
<td align="right" valign="top">Number of bedrooms:</td>
<td><select size="5" name="bedrooms"
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select></td>
</tr>
<tr>
<td>
<br>
<br>
</td>
</tr>
<tr>
<td align="right" valign="top">Number of Bathrooms:</td>
<td><select size="3" name="bathrooms"
<option>1</option>
<option>1 1/2</option>
<option>2</option>
</select></td>
</tr>
<tr>
<td>
<br>
<br>
</td>
</tr>
<tr>
<td align="right" valign="top">Washer and Dryer Connections:</td>
<td><select size="2" name="washer"
<option>Yes</option>
<option>No</option>
</select></td>
</tr>
<tr>
<td>
<br>
<br>
<td>
</tr>
<tr>
<td align="right" valign="top">Pets:</td>
<td><select size="2" name="pets"
<option>Yes</option>
<option>No</option>
</select></td>
</tr>
<tr>
<td>
<br>
<br>
</td>
</tr>
<td align="right" valign="top">Contact by:</td>
<td><select size="2" name="contact"
<option>Telephone</option>
<option>E-Mail</option>
</select></td>
</tr>
<tr>
<td align="right" valign="top">Comments:</td>
<td><textarea name="MsgBody" cols="40" rows="6"></textarea>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit"
value="Send">
</td>
</tr>
</table>
</form>
<?php
} else {
error_reporting(0);
// initialize a array to
//hold any errors we encounter
$errors = array();
// test to see if the form was actually
// posted from our form
$page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if (!ereg($page, $_SERVER['HTTP_REFERER']))
$errors[] = "Invalid referer<br>\n";
// check to see if all required data was entered
if (!$_POST['FirstName'])
$errors[] = "First Name is required to be entered.";
if (!$_POST['LastName'])
$errors[] = "Last Name is required to be entered.";
if (!$_POST['Telephone'])
$errors[] = "Telephone Number is required to be entered.";
if (!$_POST['Email'])
$errors[] = "An Email address must be entered.";
if (!$_POST['MoveIn'])
$errors[] = "An approximate move-in date must be entered.";
// if there are any errors, display them
if (count($errors)>0) {
foreach($errors as $err)
echo "$err<br>\n";
echo "<br>Please use your browser's Back button to fix.";
} else {
// no errors, so we build our message
$recipient = 'MyEmail@gmail.com';
$subject = "Real Estate Information Request";
$from = stripslashes($_POST['FirstName']);
$msg = "Message sent by $from\n";
$msg.= "\nFirst Name: ".$_POST['FirstName'];
$msg.= "\nLast Name: ".$_POST['LastName'];
$msg.= "\nTelephone Number: ".$_POST['Telephone'];
$msg.= "\nCell Phone Number:";
$cell=stripslashes($_POST['Cell']);
if ($cell)
$msg.=" $cell";
else
$msg.=" none";
$msg.="\nWork Phone Number:";
$work=stripslashes($_POST['Work']);
if ($work)
$msg.=" $work";
else
$msg.=" none";
$msg.="\nEmail Address: ".$_POST['Email'];
$msg.="\nApproximate Move-In date: ".$_POST['MoveIn'];
$msg.="\nI'd like to see ";
$apartment=($_POST['apartment'])?"Apartment: Yes":"Apartment: No";
$house=($_POST['house'])?"House: Yes":"House: No";
$condo=($_POST['condo'])?"Condo: Yes":"Condo: No";
$loft=($_POST['loft'])?"Loft: Yes":"Condo: No";
$msg.="\n$apartment\n$house\n$condo\n$house";
$msg.="\nAreas of Interest are";
# $lakeway=($_POST['lakeway'])?"Lakeway: Yes":"Lakeway: No";

if (mail($recipient,$subject,$msg)){
echo "<p>Your information has been sent!</p>";
echo nl2br($msg);
} else
echo "An unknown error occurred.";
}
}
?>
</body>
</html>

If I could at least get the "An unknown error occurred, i may have a clue. No errors appear in my access or error logs.
 
Old 09-06-2005, 11:30 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 125Reputation: 125
Perhaps you want to comment out the error_reporting(0) line to see if you do have any errors?
 
Old 09-07-2005, 11:15 PM   #3
czarherr
Member
 
Registered: Sep 2003
Location: Suwon, Korea
Distribution: Slackware 14
Posts: 288

Original Poster
Rep: Reputation: 32
and thank you. Upon doing that, I found out the php mail function wasn't supported, because i didnt compile php with sendmail installed. It all works just fine now, thats a lot.
 
Old 09-07-2005, 11:17 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 125Reputation: 125
No problem. The errors can be helpful.

Glad you got it working.
 
Old 09-08-2005, 12:03 AM   #5
tonyfreeman
Member
 
Registered: Sep 2003
Location: Fort worth, TX
Distribution: Debian testing 64bit at home, EL5 32/64bit at work.
Posts: 196

Rep: Reputation: 30
Couple of things

First thing: Your form declaration in the html doesn't need to have all that php to figure out the action for the form. So just replace your form line with this:

Code:
Replace:
<form name="form1" method="post" action="<?=$me?>">
With:
<form name="form1" method="post" action="">
... and remove that php stuff that figures the $me variable.

Next at the very end of your form you immediatly have a "<?php } else {" doesn't fit anymore because you removed that block of code at the top of the page. So ... remove that and the next line that declares 0 error reporting.

Code:
Remove:
 } else {
error_reporting(0);
Next ... that entire block of php code at the bottom of your post should be moved to the very top of the file. This way when you click the "send" button, it will reenter that php page and get processed. The top of the page is a great place to put some debugging code like print_r() or var_dump(). Here is an example of what I'm talking about:

Code:
<?php

preprint_r($_POST);  // THIS WILL SHOW YOU WHAT FORM DATA IS BEING SENT TO THIS PAGE

// -----------------------------------
// PROCESS FORM DATA
// -----------------------------------

if (isset($_POST['Submit']) && $_POST['Submit'] == 'Send') {

       // YOUR BLOCK OF CODE GOES HERE

}

// -----------------------------------
// DEFAULT PAGE
// -----------------------------------
?>

<!--  YOUR HTML FORM GOES HERE -->
-- Tony

Last edited by tonyfreeman; 09-08-2005 at 12:07 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Mail() Problem w/ Sendmail jusme Linux - Software 6 08-18-2012 03:35 PM
Squerril mail login.php path problem tkmuthuvel Linux - Networking 1 10-13-2005 11:26 PM
coding problem on php auto send mail after a period akamaru607 Programming 12 09-01-2005 08:48 AM
Cannot send mail with mail() command in PHP 4.3.4, Apache 2.0.48, Mandrake Linux 10 arcanum Linux - General 3 06-27-2004 07:06 PM
php mail() problem sashhoney Linux - Software 3 09-30-2003 06:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration