Current location: Hot Scripts Forums » Programming Languages » PHP » adding more variables to the mail() result


adding more variables to the mail() result

Reply
  #1 (permalink)  
Old 08-27-03, 09:22 PM
spinicrus spinicrus is offline
Newbie Coder
 
Join Date: Jun 2003
Location: else where
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Question adding more variables to the mail() result

hello

take a look at the following script:

(taken from http://www.sitepoint.com/article/679/5)



PHP Code:

<?php

// Read POST request params into global vars
$to      'my_email@server.com';
$from    $_POST['from'];
$subject $_POST['subject'];
$message $_POST['message'];

// Obtain file upload vars
$fileatt      $_FILES['fileatt']['tmp_name'];
$fileatt_type $_FILES['fileatt']['type'];
$fileatt_name $_FILES['fileatt']['name'];

$headers "From: $from";

if (
is_uploaded_file($fileatt)) {
  
// Read the file to be attached ('rb' = read binary)
  
$file fopen($fileatt,'rb');
  
$data fread($file,filesize($fileatt));
  
fclose($file);

  
// Generate a boundary string
  
$semi_rand md5(time());
  
$mime_boundary "==Multipart_Boundary_x{$semi_rand}x";
  
  
// Add the headers for a file attachment
  
$headers .= "\nMIME-Version: 1.0\n" .
              
"Content-Type: multipart/mixed;\n" .
              
" boundary=\"{$mime_boundary}\"";

  
// Add a multipart boundary above the plain message
  
$message "This is a multi-part message in MIME format.\n\n" .
             
"--{$mime_boundary}\n" .
             
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
             
"Content-Transfer-Encoding: 7bit\n\n" .
             
$message "\n\n";

  
// Base64 encode the file data
  
$data chunk_split(base64_encode($data));

  
// Add file attachment to the message
  
$message .= "--{$mime_boundary}\n" .
              
"Content-Type: {$fileatt_type};\n" .
              
" name=\"{$fileatt_name}\"\n" .
              
//"Content-Disposition: attachment;\n" .
              //" filename=\"{$fileatt_name}\"\n" .
              
"Content-Transfer-Encoding: base64\n\n" .
              
$data "\n\n" .
              
"--{$mime_boundary}--\n";
}

// Send the message
$ok = @mail($to$subject$message$headers);
if (
$ok) {
  echo 
"<p>Mail sent! Yay PHP!</p>";
} else {
  echo 
"<p>Mail could not be sent. Sorry!</p>";
}
?>

now the problem:


this script is working just fine, as it is... but i need to adapt it to my needs, so i have to add more variables to the mail result, (fields like nickname, gender, age, location, etc). i tried to introduce more variables right into the mail(), but there was no use... please help me, i really need this to work...
thank you in advance
Reply With Quote
  #2 (permalink)  
Old 08-27-03, 11:02 PM
Cagez's Avatar
Cagez Cagez is offline
Eeew, dirty!
 
Join Date: Jun 2003
Location: Toronto, Ontario
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Just add it to the message variable

PHP Code:

<?php


// Read POST request params into global vars
$to      'my_email@server.com';
$from    $_POST['from'];
$subject $_POST['subject'];
$message $_POST['message'];
/////////////////////////////////////////////
// add whatever you want; ex:
/////////////////////////////////////////////
$message .= "\nNickname: ".$POST['nickname'];
$message .= "\nGender: ".$_POST['gender'];
$message .= "\nAge: ".$_POST['age'];
$message .= "\nLocation: ".$_POST['location'];
Reply With Quote
  #3 (permalink)  
Old 08-27-03, 11:10 PM
spinicrus spinicrus is offline
Newbie Coder
 
Join Date: Jun 2003
Location: else where
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
ok, is working !
thank you very much !

but now i'm facing another problem :

how can i set the max file size for upload and sent in this script ?
Reply With Quote
  #4 (permalink)  
Old 08-28-03, 03:23 PM
Cagez's Avatar
Cagez Cagez is offline
Eeew, dirty!
 
Join Date: Jun 2003
Location: Toronto, Ontario
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
lol I didn't even notice it was a file attachemnet part to it

PHP Code:

// Obtain file upload vars

$fileatt      $_FILES['fileatt']['tmp_name'];
$fileatt_type $_FILES['fileatt']['type'];
$fileatt_name $_FILES['fileatt']['name'];

////////////////////////////////////////////
// check for size
////////////////////////////////////////////
$max_size 10000// max file size in bytes
if($_FILES['fileatt']['size'] > $max_size)
{
    
// too big, give error
    
die("Sorry, your file is too large!");

Reply With Quote
  #5 (permalink)  
Old 08-28-03, 03:26 PM
Cagez's Avatar
Cagez Cagez is offline
Eeew, dirty!
 
Join Date: Jun 2003
Location: Toronto, Ontario
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Also, there's a special hidden field that will tell the browser the max size:

Code:
<input type="hidden" name="MAX_FILE_SIZE" value="10000" />
Reply With Quote
  #6 (permalink)  
Old 08-28-03, 04:16 PM
spinicrus spinicrus is offline
Newbie Coder
 
Join Date: Jun 2003
Location: else where
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
i knew about the special MAX_FILE_SIZE, but that is not working all the time... anyway, i made the modifications you told me about, and is working,

thanks a lot !
Reply With Quote
  #7 (permalink)  
Old 08-28-03, 04:55 PM
ermau's Avatar
ermau ermau is offline
Wannabe Coder
 
Join Date: Aug 2003
Location: Florida, USA
Posts: 240
Thanks: 0
Thanked 0 Times in 0 Posts
Also, to make it so that it doesn't matter what or how many inputs you have, you can do this:

PHP Code:

foreach ($_POST AS $key => $value)

{
     
$message .= $key.' = '.$value.'\n';

The only problem with that is it'll show your to/from stuff again but it makes it so that it doesn't matter what inputs you have, they'll show up.
__________________
PHP / mySQL Developer
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Send email by ASP mail nghiapk ASP 1 07-09-03 12:47 AM
send mail to user onlynils New Members & Introductions 1 07-04-03 01:18 PM
No mail when reply is posted to a thread. phpkid HotScripts Site Bug Reports 5 06-24-03 11:45 AM


All times are GMT -5. The time now is 06:39 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.