Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 13th, 2004, 07:36 PM
Registered User
 
Join Date: Jan 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 15 adv_mail.php

Has anyone tried the code in chapter 15 for adv_mail.php

It does not allow me to send .hml files or .php files as attachements...anyone know why??

Reply With Quote
  #2 (permalink)  
Old January 14th, 2004, 02:41 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

Neither Rich nor I have the book. (Right Rich?) Anyway, you should be able to send any files you want as attachments. Perhaps there's a bug in the code. If so, feel free to post the relevant snippets that you think are causing the problem and we can take a look.

Also, if you need a fully-functional mail script, look at the HTML Mime Mail class:
  http://www.phpguru.org/mime.mail.html

And PEAR's version:
  http://pear.php.net/manual/en/packag....mail-mime.php


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #3 (permalink)  
Old January 14th, 2004, 03:43 PM
Registered User
 
Join Date: Jan 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the code as provided in the download area...

<?php
//adv_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%">Attachment</TH>
      <TD WIDTH="70%"><INPUT TYPE="FILE" NAME="userfile"></TD>
   </TR>
   <TR>
      <TH ALIGN="CENTER" WIDTH="30%">Type</TH>
      <TD WIDTH="70%">
      <INPUT TYPE="RADIO" VALUE="text" NAME="mail_type" CHECKED>TEXT
      <INPUT TYPE="RADIO" VALUE="html" NAME="mail_type">HTML</TD>
   </TR>
   <TR>
      <TH ALIGN="CENTER" WIDTH="30%">Encoding</TH>
      <TD WIDTH="70%">
      <INPUT TYPE="RADIO" VALUE="7bit" NAME="mail_encoding" CHECKED>7BIT
      <INPUT TYPE="RADIO" VALUE="8bit" NAME="mail_encoding">8BIT</TD>
   </TR>
   <TR>
      <TH ALIGN="CENTER" WIDTH="30%">Character Set</TH>
      <TD WIDTH="70%">
      <INPUT TYPE="RADIO" VALUE="us-ascii" NAME="mail_charset" CHECKED>US-ASCII
      <INPUT TYPE="RADIO" VALUE="euc-kr" NAME="mail_charset">EUC-KR</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;
   global $userfile, $userfile_type, $userfile_name, $userfile_size;
   global $mail_type, $mail_charset, $mail_encoding;

   $mail_parts["mail_type"] = $mail_type;
   $mail_parts["mail_charset"] = $mail_charset;
   $mail_parts["mail_encoding"] = $mail_encoding;

   $mail_parts["userfile"] = $userfile;
   $mail_parts["userfile_type"] = $userfile_type;
   $mail_parts["userfile_name"] = $userfile_name;
   $mail_parts["userfile_size"] = $userfile_size;


   $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"];

   $mail_type = $mail_parts["mail_type"];
   $mail_charset = $mail_parts["mail_charset"];
   $mail_encoding = $mail_parts["mail_encoding"];

   $userfile = $mail_parts["userfile"];
   $userfile_type = $mail_parts["userfile_type"];
   $userfile_name = $mail_parts["userfile_name"];
   $userfile_size = $mail_parts["userfile_size"];

   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);

   if($userfile_size > 0)
   {
      $mail_boundary = md5(uniqid(time()));
      $mail_headers .= "MIME-Version: 1.0\r\n";
      $mail_headers .= "Content-type: multipart/mixed;
                                      boundary=\"$mail_boundary\"\r\n\r\n";
      $mail_headers .= "This is a multi-part message in MIME format.\r\n\r\n";

      $fp = fopen($userfile, "r");
      $file = fread($fp, filesize($userfile));
      $file = chunk_split(base64_encode($file));

      $new_mail_body = "--$mail_boundary\r\n";
      $new_mail_body .= "Content-type:text/plain;charset=$mail_charset\r\n";
      $new_mail_body .= "Content-transfer-encoding:$mail_encoding\r\n\r\n";
      $new_mail_body .= "$mail_body\r\n";
      $new_mail_body .= "--$mail_boundary\r\n";
      if(!empty($userfile_type)) $mime_type = $userfile_type;
      else $mime_type = "application/octet-stream";

      $new_mail_body .= "Content-type:$mime_type;name=$userfile_name\r\n";
      $new_mail_body .= "Content-transfer-encoding:base64\r\n\r\n";
      $new_mail_body .= $file . "\r\n\r\n";
      $new_mail_body .= "--$mail_boundary--";
      $mail_body = $new_mail_body;
   }
   else if($mail_type == 'html')
   {
      $mail_headers .= "Content-type: text/html; charset=$mail_charset\r\n";
      $mail_headers .= "Content-transfer-encoding:$mail_encoding\r\n\r\n";
   }
   else
   {
      $mail_headers .= "Content-type: text/plain; charset=$mail_charset\r\n";
      $mail_headers .= "Content-transfer-encoding:$mail_encoding\r\n\r\n";
   }

   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;
}
?>

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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
Error in simple_mailer.php ( Chapter 15 ) dwfresh Beginning PHP 3 November 26th, 2003 08:25 PM



All times are GMT -4. The time now is 01:39 AM.


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