php message problems need help
Posted: Sat May 05, 2007 7:12 pm
Weirdan | Please use
message.inc file:
so if there is anyone that understands .inc files along with php then please help.
Weirdan | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Ok here is my problem. I am fairly new to php and I have written a script that will be used to send me an email from a person on my site. the problem is that when i try to load the page it loads blank and I get nothing in an error file. I have no access to the .htaccess file do to the site being on a remote server not my own. so I am going to give the code to both files that are being used. there permissions are also set to 774.
message.php file:Code: Select all
<?php
include "message.inc";
$contact = new contactform();
$contact->DisplayForm();
?>Code: Select all
<?php
// First, make sure the form was posted from a browser.
// For basic web-forms, we don't care about anything
// other than requests from a browser:
if(!isset($_SERVER['HTTP_USER_AGENT'])){
die("Forbidden - You are not authorized to view this page");
exit;
}
// Attempt to defend against header injections:
$badStrings = array("Content-Type:",
"MIME-Version:",
"Content-Transfer-Encoding:",
"bcc:",
"cc:");
// Loop through each POST'ed value and test if it contains
// one of the $badStrings:
foreach($_POST as $k => $v){
foreach($badStrings as $v2){
if(strpos($v, $v2) !== false){
logBadRequest();
header("HTTP/1.0 403 Forbidden");
exit;
}
}
}
// Made it past spammer test, free up some memory
// and continue rest of script:
unset($k, $v, $v2, $badStrings);
class contactform
{
var $toaddress;
var $name;
var $email;
var $subject;
var $message;
var $errmsg;
var $error;
var $outmessage;
var $headers;
function contactform()
{
$this->toaddress = "webmaster@newberryautomotive.com";
// $this->toaddress = "webmaster@newberryautomotive.com,rnewby22@yahoo.com";
if(isset($_POST['sendmail']))
$this->parseform();
$this->debugLog();
$this->outmessage = "";
$this->headers = "";
$this->email = "";
function parseform()
{
if ($_POST['email'])
{
$this->email = $_POST['email'];
}
else
{
$this->error = 1;
$this->errmsg = "You must enter your email addres.";
}
if ($_POST['name'])
{
$this->name = $_POST['name'];
if (!$this->error)
{
$this->headers .= "From: " . $this->email . "\r\n";
// $this->senders .= "From: " . $this->email . " (" . $this->name . ")\r\n";
// $this->headers .= "From: " . $this->name . " <" . $this->email . ">\r\n";
$this->outmessage .= "From: " . $this->name . "\n";
// $this->outmessage .= "Email: " . $this->email . "\n";
}
}
else
{
$this->error = 1;
$this->errmsg = "You must enter your name.";
}
if ($_POST['message'])
{
$this->subject .= "Message From: " .$this->name;
$this->message = $_POST['message'];
$this->outmessage .= "Message:\n" . $this->message;
}
else
{
$this->error = 1;
$this->errmsg = "You must enter your message.";
}
if (!$this->error)
{
if (!preg_match("/Content\-Type\:/i", $this->headers))
// if ($this->subject)
// if (!strstr($this->subject,$this->toaddress))
{
// if (mail($this->email, $this->toaddress, $this->subject, $this->outmessage)) //doesn't work!
if (mail($this->toaddress, $this->subject, $this->outmessage, $this->email)) //this works but uses my email for the From: header.
// if (mail($this->toaddress, $this->subject, $this->headers, $this->outmessage))
// if (mail($this->headers, $this->toaddress, $this->subject, $this->outmessage))
{
$this->errmsg = "Your message was sucessfully sent. Do NOT Refresh this page!";
}
else
{
$this->errmsg = "Your message was <b>NOT</b> sent. " . $this->email . " Was not accepted. Please try again later.";
}
}
}
$this->debugLog();
}
function DisplayForm()
{
?>
<br>
<table width="90%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td colspan="2" align="left" valign="top"><?php
if (isset($this->errmsg))
{
print '<h3><center><b>' . $this->errmsg . '</h3></center></b><p><br>';
}
?>
<form action="feedback2.php" method="post" name="FormName" enctype="application/x-www-form-urlencoded">
<font face="arial" color="black" size="3"><center>
<b>* Name:</b><br>
<input type="text" name="name" size="34" border="0">
</dl>
<dl>
<b>* Email Address:</b><br>
<input type="text" name="email" size="34" border="0"><p>
</dl>
<dl>
<b>* Message</b>:<br>
<textarea name="message" rows="12" cols="54"></textarea><p><p>
</dl>
<input type="submit" name="sendmail" value="Send Message" border="0">
<input type="reset" value="Clear Form">
</dl>
</form><br>
<center>* A required field.</center>
</td>
</tr>
</table>
<br>
<br>
<?php
}
function debugLog()
{
if (!($fp = fopen('/tmp/debug.txt', 'w')))
return;
$this->showvalues("ENV", &$_ENV, $fp);
$this->showvalues("SESSION", &$_SESSION, $fp);
$this->showvalues("COOKIE", &$_COOKIE, $fp);
$this->showvalues("SERVER", &$_SERVER, $fp);
$this->showvalues("POST", &$_POST, $fp);
$this->showvalues("GET", &$_GET, $fp);
fclose($fp);
}
function showvalues($prefix, $array, $file)
{
foreach($array as $key => $value)
{
fwrite($file, sprintf("%s: %s => %s\n", $prefix, $key, $value));
// fwrite($file, sprintf("%s: %s %s (%s)%s-%s", $toaddress, $name, $email, $phoneareacode, $phoneprefix, $phonesuffix));
// fwrite($file, sprintf("%s: %s %s %s %s \n", $messagetype, $subject, $comment, $errmsg, $error));
}
}
}
?>Weirdan | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Thanks
email@removed.com
[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]7.[/b] Do not divulge anyone's personal information in the forum - [b]including your own[/b]. This includes [b]e-mail addresses[/b], IP addresses, age, house address, and any other individual information.[/quote]