19, July 2008

about email with attachment - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: about email with attachment
« previous next »
Pages: [1] Print

Author Topic: about email with attachment  (Read 825 times)
Bill Cosby is my Father
*
Posts: 4
28 credits
Members referred : 0


« on: Mar 19, 2007, 05:14:22 PM »

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!!
« Last Edit: Mar 19, 2007, 05:43:11 PM by Taka »
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7967
40759 credits
Members referred : 3



« Reply #1 on: Mar 19, 2007, 05:41:30 PM »

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.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Bill Cosby is my Father
*
Posts: 4
28 credits
Members referred : 0


« Reply #2 on: Mar 19, 2007, 05:44:52 PM »

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?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7967
40759 credits
Members referred : 3



« Reply #3 on: Mar 19, 2007, 06:00:30 PM »

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

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Bill Cosby is my Father
*
Posts: 4
28 credits
Members referred : 0


« Reply #4 on: Mar 19, 2007, 06:22:56 PM »

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~!
« Last Edit: Mar 19, 2007, 06:26:24 PM by Taka »
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7967
40759 credits
Members referred : 3



« Reply #5 on: Mar 19, 2007, 06:39:33 PM »

I am sorry I am a busy man too Smiley

You may want to check those regarding file uploads :

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

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Bill Cosby is my Father
*
Posts: 4
28 credits
Members referred : 0


« Reply #6 on: Mar 19, 2007, 06:44:44 PM »

I am sorry I am a busy man too Smiley

You may want to check those regarding file uploads :

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

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

« Last Edit: Mar 19, 2007, 07:02:29 PM by Taka »
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6277
38488 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: Mar 20, 2007, 12:25:35 AM »

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 Visit through proxy


check the notes inside the example


Last blog : 4th of July Lottery from TemplateMonster.com
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=6259
Tags : attachment Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: about email with attachment
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jul 19, 2008, 07:03:02 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 35.662
Total Topics: 7.373
Total Members: 3.693
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: talelmouaada

18 Guests, 2 Users online :

12 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.