Results 1 to 3 of 3

Thread: php code for sending mail with attachment

  1. #1
    Davisricky is offline Senior Member
    Join Date
    Dec 2009
    Posts
    331
    Rep Power
    3

    Default php code for sending mail with attachment

    Hi everyone, I am working on one live project where I use python programming language. In my one form I want to send a email with attachment. I tried different code but everyone give error message. If you have any valuable code then let me know that it is highly appreciated.

  2. #2
    Garcíarobine is offline Senior Member
    Join Date
    Dec 2009
    Posts
    334
    Rep Power
    3

    Default

    The script that I have mentioned below will definitely help you.

    Code:
    <?php
     = 'youraddress@example.com';
     = 'Test HTML email'; 
     = md5(date('r', time())); 
     = "From: webmaster@example.comrnReply-To: webmaster@example.com";
     .= "rnContent-Type: multipart/alternative; boundary="PHP-alt-".."""; 
    ob_start(); //Turn on output buffering
    ?>
    --PHP-alt-<?php echo ; ?>  
    Content-Type: text/plain; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit
    Hello World!!! 
    This is simple text email message. 
    --PHP-alt-<?php echo ; ?>  
    Content-Type: text/html; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit
    <h2>Hello World!</h2>
    <p>This is something with <b>HTML</b> formatting.</p> 
    --PHP-alt-<?php echo ; ?>--
    <?
     = ob_get_clean();
     = @mail( , , ,  );
    echo  ? "Mail sent" : "Mail failed";
    ?>
    **)
    I have tried the given code but it didn’t solve my problem. Please try to provide some other solution.

  3. #3
    RodríguezBrown is offline Senior Member
    Join Date
    Dec 2009
    Posts
    322
    Rep Power
    3

    Default

    Follow the code which is mentioned below to get rid of this situation.

    Code:
    <?php 
    function mail_attachment(, , , , ,, , ) { 
         = .; 
         = filesize(); 
         = fopen(, "r"); 
         = fread(, ); 
        fclose(); 
         = chunk_split(base64_encode()); 
         = md5(uniqid(time())); 
         = basename(); 
         = "From: ".." <"..">rn"; 
         .= "Reply-To: ".."rn"; 
         .= "MIME-Version: 1.0rn"; 
         .= "Content-Type: multipart/mixed; boundary=""..""rnrn"; 
         .= "This is a multi-part message in MIME format.rn"; 
         .= "--".."rn"; 
         .= "Content-type:text/plain; charset=iso-8859-1rn"; 
         .= "Content-Transfer-Encoding: 7bitrnrn"; 
         .= ."rnrn"; 
         .= "--".."rn"; 
         .= "Content-Type: application/octet-stream; name=""..""rn"; // use diff. tyoes here 
         .= "Content-Transfer-Encoding: base64rn"; 
         .= "Content-Disposition: attachment; filename=""..""rnrn"; 
         .= ."rnrn"; 
         .= "--".."--"; 
        if (mail(, , "", )) { 
            echo = "mail send ... OK"; // or use booleans here 
        } else { 
            echo = "mail send ... ERROR!"; 
        } 
    }

Similar Threads

  1. Asp.net code for sending sms
    By MyersGray in forum Programming
    Replies: 2
    Last Post: 07-23-2010, 03:41 PM
  2. Asp.net code for sending mail
    By OrtizCooper in forum Programming
    Replies: 1
    Last Post: 07-15-2010, 02:43 PM
  3. Html code for sending SMS
    By Brownchris in forum General Internet Terms
    Replies: 1
    Last Post: 07-13-2010, 02:47 PM
  4. Why won't my e-mail attachment get sent?
    By Gavin Broght in forum General Networking
    Replies: 1
    Last Post: 12-20-2009, 12:44 AM
  5. How do I open an e-mail attachment that ends in .mim?
    By Jairus Clovelly in forum Networking Jargons
    Replies: 1
    Last Post: 12-20-2009, 12:41 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48