28, May 2012

about email with attachment - webmaster forum

 
Webdigity webmaster forums
[ 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
Instabuck - The easy way to sell digital products online

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


« on: Mar 19, 2007, 04: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, 04:43:11 pm by Taka »
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #1 on: Mar 19, 2007, 04: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 or twitter

Last blog : Butterfly Marketing 2.0
Bill Cosby is my Father
*
Posts: 4
28 credits
Members referred : 0


« Reply #2 on: Mar 19, 2007, 04: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: 5799
46391 credits
Members referred : 3



« Reply #3 on: Mar 19, 2007, 05: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 or twitter

Last blog : Butterfly Marketing 2.0
Bill Cosby is my Father
*
Posts: 4
28 credits
Members referred : 0


« Reply #4 on: Mar 19, 2007, 05: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, 05:26:24 pm by Taka »
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #5 on: Mar 19, 2007, 05: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
http://www.finalwebsites.com/snippets.php?id=7

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Bill Cosby is my Father
*
Posts: 4
28 credits
Members referred : 0


« Reply #6 on: Mar 19, 2007, 05: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
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 ?

« Last Edit: Mar 19, 2007, 06:02:29 pm by Taka »
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: Mar 19, 2007, 11:25:35 pm »

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

Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=6259
Tags : attachment Bookmark this thread : Digg Del.icio.us Dzone more....

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?
May 28, 2012, 06:55:50 pm





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!






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