Sublime directory Surf the web anonymous Pagerank Monitor


about email with attachment

Taka
Mon 19 March 2007, 04:14 pm GMT +0100
Quote

<?php

$toemail = $_POST['toemail'];
$fromemail = "testing@gmail.com";
$subject = $_POST['subject'];
$attachments = $HTTP_POST_FILES['attach'];
$message = $_POST['message'];

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $toemail)) {
  echo "<h4>Invalid email address</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
  echo "<h4>No subject</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}

else{

function send_mail($toemail, $fromemail, $subject, $message, $attachments=flase)
{
  $eol="\r\n";
  $mime_boundary=md5(time());

  $headers .= 'From: Taka<'.$fromemail.'>'.$eol;
  $headers .= 'Reply-To: Taka<'.$fromemail.'>'.$eol;
  $headers .= 'Return-Path: Taka<'.$fromemail.'>'.$eol;
  $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
  $headers .= "X-Mailer: PHP v".phpversion().$eol;

  $headers .= 'MIME-Version: 1.0'.$eol;
  $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
   
  $msg="";


 
  if ($attachments !== false)
  {

   for($i=0; $i < count($attachments); $i++)
   {
     if (is_file($attachments[$i]["file"]))
     { 
       $file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1));
       
       $handle=fopen($attachments[$i]["file"], 'rb');
       $f_contents=fread($handle, filesize($attachments[$i]["file"]));
       $f_contents=chunk_split(base64_encode($f_contents));    //Encode The Data For Transition using base64_encode();
       fclose($handle);
       
       $msg .= "--".$mime_boundary.$eol;
       $msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol;
       $msg .= "Content-Transfer-Encoding: base64".$eol;
       $msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
       $msg .= $f_contents.$eol.$eol;
       
     }
   }

 # Setup for text OR html
  $msg .= "Content-Type: multipart/alternative".$eol;
 
  # HTML Version
  $msg .= "--".$mime_boundary.$eol;
  $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
  $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  $msg .= $message.$eol.$eol;
  $msg .= "--".$mime_boundary."--".$eol.$eol; 


 ini_set(send_mail,$fromemail);  // the INI lines are to force the From Address to be used !
  mail($toemail, $subject, $msg, $headers);
  ini_restore(send_mail);
  echo "mail sent successfully";
}
}

}
send_mail($toemail, $fromemail, $subject, $attachments, $message);
?>

My input fields form names are:

   To: ($toemail)
   Subject: ($subject)
   File Attachment ($attach)
   Message ($message)

what's wrong with my script?Mr. Olaf?
When i received...it shows nothing in attachment with 0kb capacity
besides that...my message content also cannot received.Anything wrong of this scripts?

Thanks!!

Nikolas
Mon 19 March 2007, 04:41 pm GMT +0100
The attachment is a file that should be in your server.

$path is the path to that file, while $filename is the name of that file.

Taka
Mon 19 March 2007, 04:44 pm GMT +0100
The attachment is a file that should be in your server.

$path is the path to that file, while $filename is the name of that file.

that mean i need to create a file?what kind of file?.txt?or i need to create a folder?
if i upload images?how?

Nikolas
Mon 19 March 2007, 05:00 pm GMT +0100
It is supposed to be the file you want to attach.

If you want to attach a file that the user uploads use the $_FILES array

Taka
Mon 19 March 2007, 05:22 pm GMT +0100
It is supposed to be the file you want to attach.

If you want to attach a file that the user uploads use the $_FILES array

How i going to retrieve the path that user upload?and pass to where?Furthermore, is it any errors part in my script?
can you give some example by using my script?tq~!

Nikolas
Mon 19 March 2007, 05:39 pm GMT +0100
I am sorry I am a busy man too :)

You may want to check those regarding file uploads :

http://php.net/manual/en/features.file-upload.php
http://www.finalwebsites.com/snippets.php?id=7

Taka
Mon 19 March 2007, 05:44 pm GMT +0100
I am sorry I am a busy man too :)

You may want to check those regarding file uploads :

http://php.net/manual/en/features.file-upload.php
http://www.finalwebsites.com/snippets.php?id=7

actually i m reading on it. Is ok.
is it the upload files same concept as attachment ?


olaf
Mon 19 March 2007, 11:25 pm GMT +0100
there is an example inside the attachm. mailer class, which use the upload class to do the job.

I don't under stand why call the snippet above the class, you need to use this script to gether with upload class mentioned by Nick:
http://www.finalwebsites.com/snippets.php?id=41


check the notes inside the example

Archive for SMF v1.00 by N.P. Valid XHTML 1.0 Transitional