How to attach a doc file with mail function in php

Discussion in 'PHP' started by dineshsingh1984, Apr 4, 2011.

  1. #1
    How to attach a doc file with mail function in php

    I'm already trying but it's not work properly my code is.......
    <?php
     
      $to = "mail@generatorsindia.org";
     
      $subject = "Quotation";
     
      $random_hash = md5(date('r', time()));
     
      $headers = "From: mail@generatorsindia.org\r\nReply-To: mail@generatorsindia.org";
     
      $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
     
      $attachment = chunk_split(base64_encode(file_get_contents("quotation.doc")));
     
      $output = "
    --PHP-mixed-$random_hash;
    Content-Type: multipart/alternative; boundary='PHP-alt-$random_hash'
    --PHP-alt-$random_hash
    Content-Type: text/plain; charset='iso-8859-1'
    Content-Transfer-Encoding: 7bit
     
    Hello World!
    This is the simple text version of the email message.
     
    --PHP-alt-$random_hash
    Content-Type: text/html; charset='iso-8859-1'
    Content-Transfer-Encoding: 7bit
     
    <h2>Hello World!</h2>
    <p>This is the <b>HTML</b> version of the email message.</p>
     
    --PHP-alt-$random_hash--
     
    --PHP-mixed-$random_hash
    Content-Type: application/zip; name=geekology.zip
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment
     
    $attachment
    --PHP-mixed-$random_hash--";
     ini_set("SMTP","173.244.173.138");
    	ini_set("smtp_port","25");
     if (mail($to, $subject, $output, $headers)) 
    	{
            echo "mail send ... OK"; // or use booleans here
        } 
    	else 
    	{
            echo "mail send ... ERROR!";
        }
    ?>
    PHP:
    from this script mail is send but file is not attach in mail (attachment is blank)

    plz help me................
    it's urgent,
    thanks..............
     
    dineshsingh1984, Apr 4, 2011 IP