Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 26th, 2003, 06:10 PM
Registered User
 
Join Date: Nov 2003
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error in simple_mailer.php ( Chapter 15 )

Hi,
I've taken the code directly form this book and tried to use it and I get this error.
Line 32
character 7
Invalid Charachter
code 0

and when I choose to run script any way, I get this code showing above my mailer form:

 "; mailer_footer(); exit; } function user_message($msg) { mailer_header(); echo ""; mailer_footer(); exit; } function mail_form() { global $PHP_SELF; ?>


please help me out !!

thanks

  #2 (permalink)  
Old November 26th, 2003, 06:16 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's not terribly helpful, can you post the exact error output and perhaps post the code on and around line 32?

It looks to me like you're closing PHP scope early (?>), and some of your PHP code is being sent to the browser as plain HTML.


Take care,

Nik
http://www.bigaction.org/
  #3 (permalink)  
Old November 26th, 2003, 06:56 PM
Registered User
 
Join Date: Nov 2003
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry about that.
Depending on when I view the page with IE or within Allaire Homesight, I get different errors:

IE
Notice: Undefined variable: line 138

Allaire Homesight, :
Error has occured in the script on this page
Line 32
character 7
Invalid Character
code 0


here is the entire page:
I think the error comes somewhere in the function error_message() and user_message() ?...

<?php
//simple_mailer.php

function mailer_header()
{
?>
<HTML>
<HEAD><TITLE>E-mailer</TITLE></HEAD>
<BODY>
<?php
}

function mailer_footer()
{
?>
</BODY>
</HTML>
<?php
}

function error_message($msg)
{
   mailer_header();
   echo "<SCRIPT>alert(\"Error: $msg\");history.go(-1)</SCRIPT>";
   mailer_footer();
   exit;
}

function user_message($msg)
{
   mailer_header();
   echo "<SCRIPT>alert(\"$msg\");history.go(-1)</SCRIPT>";
   mailer_footer();
   exit;
}

function mail_form()
{
   global $PHP_SELF;
?>
<FORM METHOD="POST" ENCTYPE="MULTIPART/FORM-DATA"
      ACTION="<?php echo $PHP_SELF ?>">
<INPUT TYPE="hidden" NAME="action" VALUE="send_mail">
<DIV ALIGN="CENTER ">
<TABLE CELLSPACING="2" CELLPADDING="5" WIDTH="90%" BORDER="1">
   <TR>
      <TH ALIGN="CENTER" WIDTH="30%">To</TH>
      <TD WIDTH="70%"><INPUT NAME="mail_to" SIZE="20"></TD>
   </TR>
   <TR>
      <TH ALIGN="CENTER" WIDTH="30%">Cc</TH>
      <TD WIDTH="70%"><INPUT NAME="mail_cc" SIZE="20"></TD>
   </TR>
   <TR>
      <TH ALIGN="CENTER" WIDTH="30%">Bcc</TH>
      <TD WIDTH="70%"><INPUT NAME="mail_bcc" SIZE="20"></TD>
   </TR>
   <TR>
      <TH ALIGN="CENTER" WIDTH="30%">From</TH>
      <TD WIDTH="70%"><INPUT SIZE="20" NAME="mail_from"></TD>
   </TR>
   <TR>
      <TH ALIGN="CENTER" WIDTH="30%">Reply-To</TH>
      <TD WIDTH="70%"><INPUT SIZE="20" NAME="mail_reply_to"></TD>
   </TR>
   <TR>
      <TH ALIGN="CENTER" WIDTH="30%">Subject</TH>
      <TD WIDTH="70%"><INPUT SIZE="40" NAME="mail_subject"></TD>
   </TR>
   <TR>
      <TH ALIGN="CENTER" WIDTH="30%">Body</TH>
      <TD WIDTH="70%"><TEXTAREA NAME="mail_body" ROWS="16"
         COLS="70"></TEXTAREA></TD>
   </TR>
   <TR>
      <TH WIDTH="100%" COLSPAN="2" ALIGN="CENTER">
         <INPUT TYPE="SUBMIT" VALUE="Send" NAME="SUBMIT">
         <INPUT TYPE="RESET" VALUE="Reset" NAME="RESET">
      </TH>
   </TR>
</TABLE>
</DIV>
</FORM>
<?php
}

function send_mail()
{
   global $mail_to, $mail_cc, $mail_bcc, $mail_from, $mail_reply_to;
   global $mail_body, $mail_subject;

   $mail_parts["mail_to"] = $mail_to;
   $mail_parts["mail_from"] = $mail_from;
   $mail_parts["mail_reply_to"] = $mail_reply_to;
   $mail_parts["mail_cc"] = $mail_cc;
   $mail_parts["mail_bcc"] = $mail_bcc;
   $mail_parts["mail_subject"] = trim($mail_subject);
   $mail_parts["mail_body"] = $mail_body;

   if(my_mail($mail_parts))
      user_message("Successfully sent an e-mail titled '$mail_subject'.");

   else error_message("An unknown error occurred while attempting to
                                 send an e-mail titled '$mail_subject'.");
}

function my_mail($mail_parts)
{
   $mail_to = $mail_parts["mail_to"];
   $mail_from = $mail_parts["mail_from"];
   $mail_reply_to = $mail_parts["mail_reply_to"];
   $mail_cc = $mail_parts["mail_cc"];
   $mail_bcc = $mail_parts["mail_bcc"];
   $mail_subject = $mail_parts["mail_subject"];
   $mail_body = $mail_parts["mail_body"];

   if(empty($mail_to)) error_message("Empty to field!");
   if(empty($mail_subject)) error_message("Empty subject!");
   if(empty($mail_body)) error_message("Empty body! ");

   $mail_to = str_replace(";", ",", $mail_to);

   $mail_headers = '';

   if(!empty($mail_from)) $mail_headers .= "From: $mail_from\n";
   if(!empty($mail_reply_to)) $mail_headers .= "Reply-to: $mail_reply_to\n";
   if(!empty($mail_cc))
            $mail_headers .= "Cc: " . str_replace(";", ",", $mail_cc) . "\n";
   if(!empty($mail_bcc))
            $mail_headers .= "Bcc: " . str_replace(";", ",", $mail_bcc) . "\n";

   $mail_subject = stripslashes($mail_subject);
   $mail_body = stripslashes($mail_body);

   return mail($mail_to,$mail_subject,$mail_body,$mail_heade rs);
}

switch ($action)
{
   case "send_mail":
      mailer_header();
      send_mail();
      mailer_footer();
      break;
   case "mail_form":
      mailer_header();
      mail_form();
      mailer_footer();
      break;
   default:
      mailer_header();
      mail_form();
      mailer_footer();
      break;
}
?>


can you see the problem ?


thanks !

  #4 (permalink)  
Old November 26th, 2003, 08:25 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Most likely, you have register_globals set to "off" in php.ini. The actual error message that PHP issues (what's shown in IE) should tell you the name of the undefined variable.

Look in php.ini (or run a <?php phpinfo(); ?> script) and verify your register globals setting.

For more info on register globals, start here:
  http://p2p.wrox.com/archive/beginnin...2002-11/17.asp

There are hundreds (if not thousands) of posts on P2P about this issue:
  http://www.google.com/search?q=site:...ster%5Fglobals


If that's not your problem, let us know.


Take care,

Nik
http://www.bigaction.org/


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP 4 chapter 15 angelic_scars BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 November 29th, 2006 08:36 AM
chapter 15 checkout3.php problem derrida BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 November 12th, 2006 10:11 AM
chapter 15 cart.php pink BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 July 18th, 2005 05:45 PM
Chapter 15 - functions.php question buzzuh BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 September 7th, 2004 08:31 AM
chapter 15 adv_mail.php ncliche BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 January 14th, 2004 03:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.