Little PHP Problem

cuemasterfl

Supreme [H]ardness
Joined
Jul 5, 2001
Messages
4,181
I have a contact us page which is no longer working properly, for some odd reason. It's been a while since I made this, but now it needs to work.

First, here's the PHP code:

Code:
<html>
<head>

<?php
// Contact subject
$subject ="$subject";
// Details
$message="$subject, $detail, $name, $phone, $customer_mail";

// Mail of sender
$mail_from="$customer_mail";
// From
$header="from: $name <$mail_from>";

// Enter your email address
$to ='[email protected]';

$send_contact=mail($to,$subject,$message,$header);

// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "Your message has been sent to Customer Service Online, LLC.<br><br>Please allow 24 hours for a reply.<br><br>Thank you!";
}
else {
echo "ERROR";
}
?>

<p>
<a href="http://www.csollc.net">Click here</a> to return to the home page.
</p>


</head>

Secondly, here's the form code:

Code:
<form name="form1" method="post" action="send_contact.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Subject:</td>
<td width="2%">&nbsp;</td>
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td>Detail:</td>
<td>&nbsp;</td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>Name:</td>
<td>&nbsp;</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
  <td>Phone:</td>
  <td>&nbsp;</td>
  <td><input name="phone" type="text" id="phone" size="50"></td>
</tr>
<tr>
<td>Email:</td>
<td>&nbsp;</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>

When the information is submitted, the email arrives but it shows ,,,,, and none of the information. I'm not very good with PHP and I can't see the problem. Many thanks for any help you can provide.
 
Anything in the error log?

(event viewer if you're on Windows, /var/log/ on linux unless you're saving it somewhere else via php.ini)
 
Your code is never actually getting the data from the forms:
$message="$subject, $detail, $name, $phone, $customer_mail";

Will correctly parse the $subject, $detail, $name, $phone, and $customer_mail into the string, as requested... but given your code, your never actually getting that data from the form.... Since PHP vars default values are "", even if never instantiated, the code is doing what it should.

To fix this, and to make your code a bit better in terms of programming standards, you really should be creating the arrays before the $message call and concatting them into the string.

So:
PHP:
$subject = $_POST["subject"];
$detail = $_POST["detail"];
$name = $_POST["name"];
$phone = $_POST["phone"];
$customer_mail = $_POST["customer_mail"];

$message = $subject & ", " & $detail & ", " & $name & ", " & $phone & ", " & $customer_mail;

That should fix it.

I don't actually know why it was working to begin with, to be honest.
 
Your code is never actually getting the data from the forms:
$message="$subject, $detail, $name, $phone, $customer_mail";

Will correctly parse the $subject, $detail, $name, $phone, and $customer_mail into the string, as requested... but given your code, your never actually getting that data from the form.... Since PHP vars default values are "", even if never instantiated, the code is doing what it should.

To fix this, and to make your code a bit better in terms of programming standards, you really should be creating the vars before the $message call and concatting them into the string.

So:
PHP:
$subject = $_POST["subject"];
$detail = $_POST["detail"];
$name = $_POST["name"];
$phone = $_POST["phone"];
$customer_mail = $_POST["customer_mail"];

$message = $subject & ", " & $detail & ", " & $name & ", " & $phone & ", " & $customer_mail;

That should fix it.

I don't actually know why it was working to begin with, to be honest.

Just correcting an incorrect word
 
It looks like the script was originally written to use register_globals. Murali got the fix for you. Use it. DO NOT re-enable register_globals - it's a hold-over from the days when PHP was an extremely hackish, dirty toy language.
 
Thanks for the reply guys. I made the changes but it's still not working. Now the email is totally blank (no more ,,,,,). I checked to make sure register_globals is off.

PHP code:

Code:
<html>
<head>

<?php
// Contact subject
$subject = $_POST["subject"];
$detail = $_POST["detail"];
$name = $_POST["name"];
$phone = $_POST["phone"];
$customer_mail = $_POST["customer_mail"];

$message = $subject & ", " & $detail & ", " & $name & ", " & $phone & ", " & $customer_mail;

// Mail of sender
$mail_from="$customer_mail";
// From
$header="from: $name <$mail_from>";

// Enter your email address
$to ='[email protected]';

$send_contact=mail($to,$subject,$message,$header);

// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "Your message has been sent to Customer Service Online, LLC.<br><br>Please allow 24 hours for a reply.<br><br>Thank you!";
}
else {
echo "ERROR";
}
?>

<p>
<a href="http://www.csollc.net">Click here</a> to return to the home page.
</p>


</head>
 
$message = $subject & ", " & $detail & ", " & $name & ", " & $phone & ", " & $customer_mail;

should be

$message = $subject . ", " . $detail . ", " . $name . ", " . $phone . ", " . $customer_mail;

"." is the string concatenation operation, not & (or + like java).
 
$message = $subject & ", " & $detail & ", " & $name & ", " & $phone & ", " & $customer_mail;

should be

$message = $subject . ", " . $detail . ", " . $name . ", " . $phone . ", " . $customer_mail;

"." is the string concatenation operation, not & (or + like java).


Oi, thanks.

I'm programming in ASP VBScript for work (which uses &), programming Java for class (+ as he stated), and my side projects are PHP (http://www.gatorschedule.net... a course catalog search for the University of Florida).

My brain uses the wrong syntax in all 3 :(
 
$message = $subject . ", " . $detail . ", " . $name . ", " . $phone . ", " . $customer_mail;

Since you're joining a list of strings w/ a common separator, I'd probably write it out like this :
Code:
implode(", ", array($subject, $detail, $name, $phone, $customer_mail))
 
Back
Top