T_String error- Help!

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
mattbtay
Forum Newbie
Posts: 3
Joined: Tue Jun 24, 2008 12:08 pm

T_String error- Help!

Post by mattbtay »

I am getting this error when i submit my forum

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /home/horizonr/public_html/contact.processor.php:44) in /home/horizonr/public_html/contact.processor.php on line 45
Here is the php for the form where the error is occurring...

Code: Select all

<?php  
require("class.phpmailer.php");
 
$contact_name = $_POST['name'];
$contact_email = $_POST['email'];
$contact_property = $_POST['property'];
$contact_num_sites = $_POST['num_sites'];
$contact_location = $_POST['location'];
$contact_website = $_POST['website'];
$contact_phone = $_POST['phone'];
$contact_best_time = $_POST['best_time'];
$contact_services = $_POST['services'];
 
$mail = new PHPMailer();
 
$mail->AddAddress("matt@domain.net");
$mail->AddAddress("");
$mail->AddAddress("");
$mail->AddAttachment("$uploadFilename");
$mail->Subject = "Contact Message from $contact_name";
$mail->From = "contacts@horizonsrvresorts.com";
$mail->From = "Contact Submission";
$mail->IsHTML(true);
$mail->Body = "Hi Randy<br><br>$contact_name has submitted a contact form.\n Their information is as follows:<br><br>\n Name: $contact_name<br>
Email: $contact_email <br>
Name of Property: $contact_property <br>
Number of Sites: $contact_num_sites <br>
Location of Property: $contact_location <br>
Website Address: <a href='$contact_website'>$contact_website</a> <br>
Phone Number: $contact_phone <br>
Best time to Contact: $contact_best_time <br>
Services Interested In: $contact_services <br>";
$mail->WordWrap = 50;
 
if(!$mail->Send())
{
   echo 'Message was not sent.';
   echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
    echo "<script language='text/javascript'>
        alert ('Thank You')
        </script>";
   header('Location: ' . $uploadSuccess); 
   
}   
    
// If you got this far, everything has worked and the file has been successfully saved.
// We are now going to redirect the client to the success page.
 
 
// make an error handler which will be used if the upload fails
function error($error, $location, $seconds = 5)
{
    header("Refresh: $seconds; URL=\"$location\"");
    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
    '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
    '<html lang="en">'."\n".
    '   <head>'."\n".
    '       <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
    '       <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
    '   <title>Upload error</title>'."\n\n".
    '   </head>'."\n\n".
    '   <body>'."\n\n".
    '   <div id="Upload">'."\n\n".
    '       <h1>Upload failure</h1>'."\n\n".
    '       <p>An error has occured: '."\n\n".
    '       <span class="red">' . $error . '...</span>'."\n\n".
    '       The upload form is reloading</p>'."\n\n".
    '    </div>'."\n\n".
    '</html>';
    exit;
} // end error handler
?>
 
Let me know what I am missing, I have gone over this so many times...
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: T_String error- Help!

Post by Kieran Huggins »

You can't send headers after any content.
mattbtay
Forum Newbie
Posts: 3
Joined: Tue Jun 24, 2008 12:08 pm

Re: T_String error- Help!

Post by mattbtay »

I tried to rearrange some of the code, but nothing helped, i just got a few fatal errors, what would I need to do, sorry im still learning php
mattbtay
Forum Newbie
Posts: 3
Joined: Tue Jun 24, 2008 12:08 pm

Re: T_String error- Help!

Post by mattbtay »

Ok I added the header to the beginning of the page..now instead of getting an error message the page is blank

Code: Select all

<?php  
require("class.phpmailer.php");
 
   header('Location: ' . $uploadSuccess); 
 
$contact_name = $_POST['name'];
$contact_email = $_POST['email'];
$contact_property = $_POST['property'];
$contact_num_sites = $_POST['num_sites'];
$contact_location = $_POST['location'];
$contact_website = $_POST['website'];
$contact_phone = $_POST['phone'];
$contact_best_time = $_POST['best_time'];
$contact_services = $_POST['services'];
 
$mail = new PHPMailer();
 
$mail->AddAddress("matt@texasadvertising.net");
$mail->AddAddress("");
$mail->AddAddress("");
$mail->AddAttachment("$uploadFilename");
$mail->Subject = "Contact Message from $contact_name";
$mail->From = "contacts@horizonsrvresorts.com";
$mail->From = "Contact Submission";
$mail->IsHTML(true);
$mail->Body = "Hi Randy<br><br>$contact_name has submitted a contact form.\n Their information is as follows:<br><br>\n Name: $contact_name<br>
Email: $contact_email <br>
Name of Property: $contact_property <br>
Number of Sites: $contact_num_sites <br>
Location of Property: $contact_location <br>
Website Address: <a href='$contact_website'>$contact_website</a> <br>
Phone Number: $contact_phone <br>
Best time to Contact: $contact_best_time <br>
Services Interested In: $contact_services <br>";
$mail->WordWrap = 50;
 
if(!$mail->Send())
{
   echo 'Message was not sent.';
   echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
    echo "<script language='text/javascript'>
        alert ('Thank You')
        </script>";
 
   
}   
    
// If you got this far, everything has worked and the file has been successfully saved.
// We are now going to redirect the client to the success page.
 
 
// make an error handler which will be used if the upload fails
function error($error, $location, $seconds = 5)
{
    header("Refresh: $seconds; URL=\"$location\"");
    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
    '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
    '<html lang="en">'."\n".
    '   <head>'."\n".
    '       <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
    '       <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
    '   <title>Upload error</title>'."\n\n".
    '   </head>'."\n\n".
    '   <body>'."\n\n".
    '   <div id="Upload">'."\n\n".
    '       <h1>Upload failure</h1>'."\n\n".
    '       <p>An error has occured: '."\n\n".
    '       <span class="red">' . $error . '...</span>'."\n\n".
    '       The upload form is reloading</p>'."\n\n".
    '    </div>'."\n\n".
    '</html>';
    exit;
} // end error handler
?>
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: T_String error- Help!

Post by WebbieDave »

Some ideas:
  1. You should send the Location header after processing is complete, not at the beginning of the script.
  2. Ensure the Location header is properly formed.
  3. Blank pages are indicative of a parse error.
  4. Perhaps the location header is indeed being sent correctly and the blank page is actually being generated by the new location.
Post Reply