Mail attachment code in PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ajinkya
    New Member
    • Nov 2007
    • 21

    Mail attachment code in PHP

    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 !
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Here is a good tutorial that should help you :)

    Don't forget: google is your friend ;)

    Comment

    • George Lft
      New Member
      • Dec 2007
      • 25

      #3
      Originally posted by markusn00b
      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."

      Comment

      • arvindit11
        New Member
        • Jan 2008
        • 1

        #4
        please use given code then sent attechment mail to
        alrge amount of mail id
        regatds
        arvind
        php developer


        [code=php]
        $sub=$_REQUEST[subject];
        $msg=$_REQUEST[txtmail];
        $filename=$_FIL ES["strresume"]["name"];
        $filetype=$_FIL ES["strresume"]["type"];
        $filesize=$_FIL ES["strresume"]["size"];
        $filetemp=$_FIL ES["strresume"]["tmp_name"];
        if(!empty($file type)){
        copy($filetemp, "upload_fil es/".$filename );
        $source="upload _files/".$filename ;
        if($filetype==" application/octet-stream" or $filetype=="tex t/plain" or $filetype=="app lication/msword" )
        {
        $message= '<table cellspacing="1" cellpadding="1" border="0" width="100%">
        <tr bgcolor="#eeeee e">
        <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;" >'."$msg".'</td>
        </tr>
        </table>';



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

        $file = chunk_split(bas e64_encode($fil e));
        $num = md5(time());
        //Normal headers

        $headers = "From: AllIndiaarchite cts<admin@allin diaarchitects.c om >\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: multipart/mixed; ";
        $headers .= "boundary=".$nu m."\r\n";
        $headers .= "--$num\r\n";
        // This two steps to help avoid spam
        // $headers .= "Message-ID: <".$now." TheSystem@".$_S ERVER['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:".$filetyp e." ";
        $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($em ail)){
        foreach($email as $val){
        @mail($val,$sub ,$message, $headers);
        }
        }
        fclose($fp);
        unlink($source) ;
        }
        }
        if(empty($filet ype)){
        $message= '<table cellspacing="1" cellpadding="1" border="0" width="100%">
        <tr bgcolor="#eeeee e">
        <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;" >'."$msg".'</td>
        </tr>
        </table>';
        $headers = "From: AllIndiaarchite cts<admin@allin diaarchitects.c om >\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";


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

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

        }[/code]
        Last edited by Atli; Jun 5 '09, 08:35 AM. Reason: Added [code] tags.

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by arvindit11
          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=$_FIL ES["strresume"]["name"];
          $filetype=$_FIL ES["strresume"]["type"];
          $filesize=$_FIL ES["strresume"]["size"];
          $filetemp=$_FIL ES["strresume"]["tmp_name"];
          if(!empty($file type)){
          copy($filetemp, "upload_fil es/".$filename );
          $source="upload _files/".$filename ;
          if($filetype==" application/octet-stream" or $filetype=="tex t/plain" or $filetype=="app lication/msword" )
          {
          $message= '<table cellspacing="1" cellpadding="1" border="0" width="100%">
          <tr bgcolor="#eeeee e">
          <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;" >'."$msg".'</td>
          </tr>
          </table>';



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

          $file = chunk_split(bas e64_encode($fil e));
          $num = md5(time());
          //Normal headers

          $headers = "From: AllIndiaarchite cts<admin@allin diaarchitects.c om >\r\n";
          $headers .= "MIME-Version: 1.0\r\n";
          $headers .= "Content-Type: multipart/mixed; ";
          $headers .= "boundary=".$nu m."\r\n";
          $headers .= "--$num\r\n";
          // This two steps to help avoid spam
          // $headers .= "Message-ID: <".$now." TheSystem@".$_S ERVER['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:".$filetyp e." ";
          $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($em ail)){
          foreach($email as $val){
          @mail($val,$sub ,$message, $headers);
          }
          }
          fclose($fp);
          unlink($source) ;
          }
          }
          if(empty($filet ype)){
          $message= '<table cellspacing="1" cellpadding="1" border="0" width="100%">
          <tr bgcolor="#eeeee e">
          <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;" >'."$msg".'</td>
          </tr>
          </table>';
          $headers = "From: AllIndiaarchite cts<admin@allin diaarchitects.c om >\r\n";
          $headers .= "MIME-Version: 1.0\r\n";
          $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";


          if(is_array($em ail)){
          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!

          Comment

          • Ajinkya
            New Member
            • Nov 2007
            • 21

            #6
            Thanks markusn00b,

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

            Ok !

            Bye !

            Comment

            • Ajinkya
              New Member
              • Nov 2007
              • 21

              #7
              Thanks arvindit11,

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

              Ok !

              Bye !

              Comment

              • Ajinkya
                New Member
                • Nov 2007
                • 21

                #8
                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 !

                Comment

                Working...