Helljumper
10-15-2012, 09:44 PM
Here is my code. All my class files and includes are valid and every other page I've wrote has worked except this one, and it's not even giving me an error message... It just gives me a blank page with absolutely no source code or anything and I don't know why. I've proofread it multiple times and cannot find the mistake; my guess is that it's within the $message variable but not sure.
Here is the code:
<?php
include 'inc.common.php';
$page = new Page ( 'Contact Us' );
?>
<h2>Contact Us</h2>
<div class="text">
<?php
if ( isset ( $_POST['send'] ) )
{
$errors = array();
$attr = array ( 'nm' => $_POST['name'],
'em' => $_POST['email'],
'sj' => $_POST['subject'],
'mg' => $_POST['message']
);
if ( strlen ( $attr['nm'] ) < 2 || strlen ( $attr['nm'] ) > 50 )
$errors[] = 'Please enter your name.';
if ( strlen ( $attr['em'] ) < 5 || strlen ( $attr['em'] ) > 70 )
$errors[] = 'Please enter a valid e-mail address.';
if ( strlen ( $attr['sj'] ) < 2 || strlen ( $attr['sj'] ) > 30 )
$errors[] = 'Please enter a subject that is between 2 and 30 characters in length.';
if ( strlen ( $attr['mg'] ) < 2 || strlen ( $attr['mg'] ) > 4000 )
$errors[] = 'Please enter a valid message.';
if ( count ( $errors ) > 0 )
{
echo ' <blockquote>' . "\n",
' <span class="alert">The following errors occurred while trying to process your request:</span>' . "\n",
' <ul>' . "\n";
foreach ( $errors as $errNo => $err )
{
echo ' <li><strong>(#' . ( $errNo + 1 ) . '):</strong> ' . $err . '</li>' . "\n";
}
echo ' </ul>' . "\n",
' </blockquote>' . "\n";
} else {
$headers = "From: $attr['em']\r\n";
$headers .= 'Content-Type: text/html';
$message = nl2br ( $attr['mg'] );
$to = '';
$body = '<tt>THIS IS A MESSAGE GENERATED BY THE CONTACT FORM AT .ORG</tt><br />
The following information was provided:<br />
<blockquote>
<strong>Name:</strong> ' . $attr['nm'] . '<br />
<strong>Subject:</strong> ' . $attr['sj'] . '<br />
<strong>Reply-To:</strong> ' . $attr['em'] . '
</blockquote>
<p><strong>Message:</strong></p>
<p>' . $message . '</p>';
$subject = 'Contact Form: ' . $attr['sj'];
mail ( $to, $subject, $body, $headers );
echo ' <blockquote>' . "\n",
' <span class="alert">Message sent successfully, expect a response within 24 hours.</span>' . "\n",
' </blockquote>' . "\n";
}
}
?>
<form action="?" method="post">
<fieldset>
<fieldset>
<legend>Your Name</legend>
<input type="text" name="name" value="" size="30" />
</fieldset>
<fieldset>
<legend>Your E-Mail Address</legend>
<input type="text" name="email" value="" size="50" />
</fieldset>
<fieldset>
<legend>Message Subject</legend>
<input type="text" name="subject" value="" size="40" />
</fieldset>
<fieldset>
<legend>Message</legend>
<textarea name="message" rows="4" cols="60"></textarea>
</fieldset>
<input type="submit" name="send" value="Send" />
</fieldset>
</form>
</div>
</div>
<?= $page->genFooter() ?>
I edited out e-mail addresses etc
Here is the code:
<?php
include 'inc.common.php';
$page = new Page ( 'Contact Us' );
?>
<h2>Contact Us</h2>
<div class="text">
<?php
if ( isset ( $_POST['send'] ) )
{
$errors = array();
$attr = array ( 'nm' => $_POST['name'],
'em' => $_POST['email'],
'sj' => $_POST['subject'],
'mg' => $_POST['message']
);
if ( strlen ( $attr['nm'] ) < 2 || strlen ( $attr['nm'] ) > 50 )
$errors[] = 'Please enter your name.';
if ( strlen ( $attr['em'] ) < 5 || strlen ( $attr['em'] ) > 70 )
$errors[] = 'Please enter a valid e-mail address.';
if ( strlen ( $attr['sj'] ) < 2 || strlen ( $attr['sj'] ) > 30 )
$errors[] = 'Please enter a subject that is between 2 and 30 characters in length.';
if ( strlen ( $attr['mg'] ) < 2 || strlen ( $attr['mg'] ) > 4000 )
$errors[] = 'Please enter a valid message.';
if ( count ( $errors ) > 0 )
{
echo ' <blockquote>' . "\n",
' <span class="alert">The following errors occurred while trying to process your request:</span>' . "\n",
' <ul>' . "\n";
foreach ( $errors as $errNo => $err )
{
echo ' <li><strong>(#' . ( $errNo + 1 ) . '):</strong> ' . $err . '</li>' . "\n";
}
echo ' </ul>' . "\n",
' </blockquote>' . "\n";
} else {
$headers = "From: $attr['em']\r\n";
$headers .= 'Content-Type: text/html';
$message = nl2br ( $attr['mg'] );
$to = '';
$body = '<tt>THIS IS A MESSAGE GENERATED BY THE CONTACT FORM AT .ORG</tt><br />
The following information was provided:<br />
<blockquote>
<strong>Name:</strong> ' . $attr['nm'] . '<br />
<strong>Subject:</strong> ' . $attr['sj'] . '<br />
<strong>Reply-To:</strong> ' . $attr['em'] . '
</blockquote>
<p><strong>Message:</strong></p>
<p>' . $message . '</p>';
$subject = 'Contact Form: ' . $attr['sj'];
mail ( $to, $subject, $body, $headers );
echo ' <blockquote>' . "\n",
' <span class="alert">Message sent successfully, expect a response within 24 hours.</span>' . "\n",
' </blockquote>' . "\n";
}
}
?>
<form action="?" method="post">
<fieldset>
<fieldset>
<legend>Your Name</legend>
<input type="text" name="name" value="" size="30" />
</fieldset>
<fieldset>
<legend>Your E-Mail Address</legend>
<input type="text" name="email" value="" size="50" />
</fieldset>
<fieldset>
<legend>Message Subject</legend>
<input type="text" name="subject" value="" size="40" />
</fieldset>
<fieldset>
<legend>Message</legend>
<textarea name="message" rows="4" cols="60"></textarea>
</fieldset>
<input type="submit" name="send" value="Send" />
</fieldset>
</form>
</div>
</div>
<?= $page->genFooter() ?>
I edited out e-mail addresses etc