473,320 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Mail attachment code in PHP

21
Hello , sir !

I am Ajinkya, I work in php. and I want to be perfect coder in php as soos as possible. And I try to my level very best. But sir, today I have a problem , can you help me !!
Sir, I want php code to , sent attachements with mail.
That is when I send mail to any friend at that I want to send some attachments with that mail , then what I want to do.
Ok !
Bye !
Jan 17 '08 #1
7 7720
Markus
6,050 Expert 4TB
Here is a good tutorial that should help you :)

Don't forget: google is your friend ;)
Jan 17 '08 #2
Here is a good tutorial that should help you :)

Don't forget: google is your friend ;)
GREAAAT link ,and yeh i agree totally " google friend."
Jan 17 '08 #3
please use given code then sent attechment mail to
alrge amount of mail id
regatds
arvind
php developer


Expand|Select|Wrap|Line Numbers
  1. $sub=$_REQUEST[subject];
  2.   $msg=$_REQUEST[txtmail];
  3.   $filename=$_FILES["strresume"]["name"];
  4.   $filetype=$_FILES["strresume"]["type"];
  5.   $filesize=$_FILES["strresume"]["size"];
  6.   $filetemp=$_FILES["strresume"]["tmp_name"];
  7.   if(!empty($filetype)){
  8.   copy($filetemp,"upload_files/".$filename);
  9.   $source="upload_files/".$filename;
  10.    if($filetype=="application/octet-stream"  or $filetype=="text/plain"   or $filetype=="application/msword" )
  11.     {
  12.     $message= '<table cellspacing="1" cellpadding="1" border="0" width="100%">
  13.               <tr bgcolor="#eeeeee">
  14.               <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'."$msg".'</td>
  15.               </tr>
  16.               </table>';
  17.  
  18.  
  19.  
  20.    $fp = fopen($source, "rb");
  21.     $file = fread($fp, filesize($source));
  22.  
  23.     $file = chunk_split(base64_encode($file));
  24.     $num = md5(time());
  25. //Normal headers
  26.  
  27.        $headers  = "From: AllIndiaarchitects<admin@allindiaarchitects.com >\r\n";
  28.        $headers  .= "MIME-Version: 1.0\r\n";
  29.        $headers  .= "Content-Type: multipart/mixed; ";
  30.        $headers  .= "boundary=".$num."\r\n";
  31.        $headers  .= "--$num\r\n";
  32. // This two steps to help avoid spam   
  33.    // $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
  34.     $headers .= "X-Mailer: PHP v".phpversion()."\r\n";         
  35.  
  36. // With message
  37.        $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
  38.        $headers .= "Content-Transfer-Encoding: 8bit\r\n";
  39.        $headers .= "".$message."\n";
  40.        $headers .= "--".$num."\n"; 
  41. // Attachment headers
  42.        $headers  .= "Content-Type:".$filetype." ";
  43.        $headers  .= "name=\"". $filename."\"r\n";
  44.        $headers  .= "Content-Transfer-Encoding: base64\r\n";
  45.        $headers  .= "Content-Disposition: attachment; ";
  46.        $headers  .= "filename=\"". $filename."\"\r\n\n";
  47.        $headers  .= "".$file."\r\n";
  48.        $headers  .= "--".$num."--";
  49. // SEND MAIL
  50.        if(is_array($email)){
  51.        foreach($email as $val){
  52.       @mail($val,$sub,$message, $headers);
  53.        }
  54.        }
  55.        fclose($fp);
  56.        unlink($source);
  57.        } 
  58.        }
  59.        if(empty($filetype)){
  60.    $message= '<table cellspacing="1" cellpadding="1" border="0" width="100%">
  61.               <tr bgcolor="#eeeeee">
  62.               <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'."$msg".'</td>
  63.               </tr>
  64.               </table>';
  65.        $headers  = "From: AllIndiaarchitects<admin@allindiaarchitects.com >\r\n";
  66.        $headers  .= "MIME-Version: 1.0\r\n";
  67.        $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
  68.  
  69.  
  70.        if(is_array($email)){
  71.        foreach($email as $val){
  72.  
  73.       @mail($val,$sub,$message, $headers);
  74.       //echo $val."<br>";
  75.        //echo $message."<br>";
  76.        }
  77.        }
  78.  
  79.        }
Jan 17 '08 #4
Markus
6,050 Expert 4TB
please use given code then sent attechment mail to
alrge amount of mail id
regatds
arvind
php developer



$sub=$_REQUEST[subject];
$msg=$_REQUEST[txtmail];
$filename=$_FILES["strresume"]["name"];
$filetype=$_FILES["strresume"]["type"];
$filesize=$_FILES["strresume"]["size"];
$filetemp=$_FILES["strresume"]["tmp_name"];
if(!empty($filetype)){
copy($filetemp,"upload_files/".$filename);
$source="upload_files/".$filename;
if($filetype=="application/octet-stream" or $filetype=="text/plain" or $filetype=="application/msword" )
{
$message= '<table cellspacing="1" cellpadding="1" border="0" width="100%">
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'."$msg".'</td>
</tr>
</table>';



$fp = fopen($source, "rb");
$file = fread($fp, filesize($source));

$file = chunk_split(base64_encode($file));
$num = md5(time());
//Normal headers

$headers = "From: AllIndiaarchitects<admin@allindiaarchitects.com >\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
// This two steps to help avoid spam
// $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";

// With message
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";
// Attachment headers
$headers .= "Content-Type:".$filetype." ";
$headers .= "name=\"". $filename."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"". $filename."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--";
// SEND MAIL
if(is_array($email)){
foreach($email as $val){
@mail($val,$sub,$message, $headers);
}
}
fclose($fp);
unlink($source);
}
}
if(empty($filetype)){
$message= '<table cellspacing="1" cellpadding="1" border="0" width="100%">
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'."$msg".'</td>
</tr>
</table>';
$headers = "From: AllIndiaarchitects<admin@allindiaarchitects.com >\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";


if(is_array($email)){
foreach($email as $val){

@mail($val,$sub,$message, $headers);
//echo $val."<br>";
//echo $message."<br>";
}
}

}
If you're going to *help* atleast use [.CODE=php]PHP code goes here.[/code]

Also, you gave no description of what your code does. The primary focus of this forum is to help people not to just supply code and expect them to understand it.

Thanks!
Jan 17 '08 #5
Ajinkya
21
Thanks markusn00b,

to give me reply . Now I try to implement this code in my application. I later inform you about implementation .

Ok !

Bye !
Jan 21 '08 #6
Ajinkya
21
Thanks arvindit11,

to reply me .
Now I try to implement this code in my application. I later inform you about implementation .

Ok !

Bye !
Jan 21 '08 #7
Ajinkya
21
Hello arvind ,

Good evening. How r u?

Can you please explain me about variables,

$sub=$_REQUEST[subject];
$msg=$_REQUEST[txtmail];

I am waiting your reply .

By !
Jan 31 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: PeterR | last post by:
I've spent weeks trying to write a function that is simple to use for sending emails with attachments, but I my programming skills are not that advanced. I've noticed a few postings in these...
2
by: knoak | last post by:
Hi there, I've found a script at these great Google fora. a script to send emails with attachments. The script is below this message, name etc. aren't mine, but from the original post. My...
1
by: theWizard1 | last post by:
The following sends my email, but the attachment is empty. The attachment should contain the data that is in the string that was created from the xmlReader. I have a stored procedure written...
6
by: rekaeps | last post by:
We are developing an ASP.NET 2.0 (C#) application, and I'm having troubles sending e-mail from the server when accessing the web site from a separate client computer. Also, in the same scenario,...
3
by: dnuos | last post by:
We are developing an ASP.NET 2.0 (C#) application, and I'm having troubles sending e-mail from the server when accessing the web site from a separate client computer. Here's some details: ...
5
by: Robert Dufour | last post by:
I am trying to use framework 1.1 - stuck with it. to send emails from a windows form application. The email messages can have attachments, usually two and they can be either text or sounds (wav...
1
by: William Connery | last post by:
Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an...
1
by: nukephp | last post by:
Hello Guys would you know about php email with his attachment Working on linux platform................................................... The code as below: mail.php <?php //define the...
1
by: maxxxxel | last post by:
Hi Can anyone help me with some asp code , I changed the code to use CDO.message instead of the old cdont.sys to send mail from a ASP webpage which works fine. Our problem is that when we send...
3
by: raj200809 | last post by:
when i m sending mail i received error from symantec Antivirus" Your email message was unable to be sent because your mail server rejected the message 550-5.7.1 the ip you’re using to send mail is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.