Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2006, 01:18 AM
Registered User
 
Join Date: Sep 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default attechment with e-mail

how to attech a file with e-mail
 
Old October 18th, 2006, 11:47 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

Hai rahulcbr,
Create a file call mail_attachment.php
and paste the following code

-------------------------------
<?php
function mail_attachment ($from , $to, $subject, $message, $attachment){
    $fileatt = $attachment; // Path to the file
    $fileatt_type = "application/octet-stream"; // File Type
    $start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;
    $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment

    $email_from = $from; // Who the email is from
    $email_subject = $subject; // The Subject of the email
    $email_txt = $message; // Message that the email has in it

    $email_to = $to; // Who the email is to

    $headers = "From: ".$email_from;

    $file = fopen($fileatt,'rb');
    $data = fread($file,filesize($fileatt));
    fclose($file);
    $msg_txt="\n\nMail created using free code from 4word systems : http://4wordsystems.com";

    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

    $headers .= "\nMIME-Version: 1.0\n" .
            "Content-Type: multipart/mixed;\n" .
            " boundary=\"{$mime_boundary}\"";

    $email_txt .= $msg_txt;

    $email_message .= "This is a multi-part message in MIME format.\n\n" .
                "--{$mime_boundary}\n" .
                "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
               "Content-Transfer-Encoding: 7bit\n\n" .
    $email_txt . "\n\n";

    $data = chunk_split(base64_encode($data));

    $email_message .= "--{$mime_boundary}\n" .
                  "Content-Type: {$fileatt_type};\n" .
                  " name=\"{$fileatt_name}\"\n" .
                  //"Content-Disposition: attachment;\n" .
                  //" filename=\"{$fileatt_name}\"\n" .
                  "Content-Transfer-Encoding: base64\n\n" .
                 $data . "\n\n" .
                  "--{$mime_boundary}--\n";


    $ok = @mail($email_to, $email_subject, $email_message, $headers);

    if($ok) {
    } else {
        die("Sorry but the email could not be sent. Please go back and try again!");
    }
}
?>


-----------------------------------

sendmail.php
<?
include 'mail_attachment.php';
mail_attachment("[email protected]", "[email protected]", "subject", "message", 'filename.jpg');
?>


surendran
(Anything is Possible)
http://ssuren.spaces.msn.com
 
Old January 24th, 2007, 04:34 PM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

why do I get this message when I hit the send button?

----------------------------------- sendmail.php
Fatal error: Cannot redeclare mail_attachment() (previously declared in /nfs/cust/9/50/27/472059/web/supreme/mail_attachment.php:2) in /nfs/cust/9/50/27/472059/web/supreme/mail_attachment.php on line 2






Similar Threads
Thread Thread Starter Forum Replies Last Post
Send mail and attachments with PHP mail function Lofa Beginning PHP 1 June 2nd, 2008 03:24 PM
problems sending mail with java mail gandacuboy J2EE 2 December 20th, 2006 03:05 PM
Sending e-mail to different mail box! Calibus Classic ASP Databases 4 September 3rd, 2004 05:48 PM
Sending both text mail and HTML mail - CDONTS madhukp Classic ASP Basics 1 October 8th, 2003 01:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.