Results 1 to 5 of 5

Thread: emailing with attachment?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    emailing with attachment?

    is using a php script on a webserver a good option for sending multiple emails with large attachment?

    currently uploading the attachment, from a local pc, multiple times, is very time consuming

    how would i pass the emails from local pc program, with arguments, to php script?

    thnx for any help

    edit: i found some code here http://www.vbforums.com/showpost.php...31&postcount=9 to send an atttachment, but it appears the data is just in the body of the email, i am testing with a text file but the files to be attached would be pdf
    Last edited by westconn1; Nov 30th, 2008 at 06:30 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: emailing with attachment?

    What exactly are you trying to do? Send a large file over the internet or attach a large file to an email.

    I would not recommend sending emails with large attachments unless you have to. If you are sending an email with an attachment you need to use multi-part format (MIME). Because SMTP is a plain text protocol, the email body and any attachments must also be sent in text (even the binary ones).

    phpman's post demonstrates how to format a multi-part message. Note that the payload of the attachment is encoded using base 64. This allows you to send the binary data in a format that is safe for transport in a text only medium.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: emailing with attachment?

    What exactly are you trying to do? Send a large file over the internet or attach a large file to an email.
    i am trying to improve the emailing method, of sending individual emails with a common attachment (pdf price list) to multiple recipients (700 - 1000)
    the current method uploads the same 700k to 1 mb attachment for each email,

    i am looking for a method to send the attachment from the server, which seemed to need to send the email from the server

    i attempted to attach a small text file to an email for testing purpose, but the email came with no attachment, but an amount of data in the body of the email, i am probably doing something wrong as i have no experience with PHP
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: emailing with attachment?

    Show us the code you used and the source of the email you received. I am sure I or someone else can assist you from there

    If you are sending the same attachment via email many times then you should upload the file once and save it locally on the server. You can then use PHP file system functions to open and read the data form the file for each email.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: emailing with attachment?

    at this stage i have just been sending email from an html form, this has been working ok, now i try to edit the php to add attachment, presuming i get that to work then i need to look at processing all the names and email address from a file or variable, and creating some sort of log, to track success /failures
    Code:
    // -------------------- END OF CONFIGURABLE SECTION ---------------
    $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
    $name = $_POST['name'] ;
    $email = $_POST['email'] ;
    $comments = $_POST['comments'] ;
    $filename = "testfile.txt";
    $http_referrer = getenv( "HTTP_REFERER" );
    if (!isset($_POST['email'])) {
    	header( "Location: $formurl" );
    	exit ;
    }
    if (empty($name) || empty($email) || empty($comments)) {
       header( "Location: $errorurl" );
       exit ;
    }
    if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
    	header( "Location: $errorurl" );
    	exit ;
    }
    if (get_magic_quotes_gpc()) {
    	$comments = stripslashes( $comments );
    }
    
    //attachments
    $userfile_type = "text";
    
    //MIME code
    $boundary = "b" . md5(uniqid(time()));
    $mime_header = "Content-type: multipart/mixed;";
    $mime_header .= "boundary = {$boundary}\r\n\r\n";
    $mime_header .= "This is a mime encoded message.\r\n\r\n";
    
    //First the regular message
    $mime_message .= "--{$boundary}\r\n";
    $mime_message .= "Content-type: {$userfile_type}\r\n";
    $mime_message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
    $mime_message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $mime_message .= "{$message}\r\n";
    
    //Now the attachment
    if(!($fp = @fopen($filename, "rb"))){
    $error = "Can't open file";
    echo $error;
    exit;
    }
    $attach = fread($fp, filesize($filename));
    $attach = chunk_split(base64_encode($attach));
    $file_name = basename($filename); // gets basename of file
    
    $mime_message .= "--$boundary\r\n";
    $mime_message .= "Content-Type: $userfile_type; name=\"{$file_name}\"\r\n";
    $mime_message .= "Content-Transfer-Encoding:base64\r\n ";
    $mime_message .= "Content-Disposition: attachment; filename=\"{$file_name}\"\r\n\r\n";
    $mime_message  .= "\r\n\r\n$attach\n";
    $mime_message .= "--{$boundary}--\r\n"; 
    
    
    $messageproper =
    	"This message was sent from:\n" .
    	"$http_referrer\n" .
    	"------------------------------------------------------------\n" .
    	"Name of sender: $name\n" .
    	"Email of sender: $email\n" .
    	"------------------------- COMMENTS -------------------------\n\n" .
    	$comments .
    	"\n\n------------------------------------------------------------\n" .
            $_SERVER['REMOTE_ADDR'] .
    	 "\n\n" .
            $mime_message;
    
    mail($mailto, $subject,  $messageproper,
    	"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: 
    
    chfeedback.php 2.08" );
    header( "Location: $thankyouurl" );
    exit ;
    some of the urls are in the configurable section i omitted

    Code:
    Return-Path: <apache@************>
    X-Original-To: ************
    Delivered-To: ************
    Received: from ************ (localhost.localdomain [127.0.0.1])
    	by ************ (Postfix) with ESMTP id AA631F0480
    	for <************>; Sun, 30 Nov 2008 22:25:39 +1100 (EST)
    Received: (from apache@localhost)
    	by ************ (8.13.1/8.13.1/Submit) id mAUBPbxJ012060;
    	Sun, 30 Nov 2008 22:25:37 +1100
    Date: Sun, 30 Nov 2008 22:25:37 +1100
    Message-Id: <200811301125.mAUBPbxJ012060@************>
    To: [email protected]
    Subject: Feedback Form
    From: "pete" <************>
    Reply-To: "pete" <************>
    X-Mailer: chfeedback.php 2.08
    MIME-Version: 1.0
    MailScanner-NULL-Check: 1228649141.11647@hQQXj3aAIKQsEIa0OxVLcQ
    X-Westconn-MailScanner-Information: Please contact the ISP for more information
    X-MailScanner-ID: AA631F0480.558E8
    X-Westconn-MailScanner: Found to be clean
    X-Westconn-MailScanner-From: apache@************
    Status: O
    X-UID: 443828
    Content-Length: 4128
    X-Keywords:                                                                                                    
    X-Antivirus: AVG for E-mail 8.0.176 [270.9.11/1817]
    
    This message was sent from:
    http://************/feedback.html
    ------------------------------------------------------------
    Name of sender: pete
    Email of sender: [email protected]
    ------------------------- COMMENTS -------------------------
    
    123
    
    ------------------------------------------------------------
    61.69.168.171
    
    --b4a9573f5eee9376fd19690bd02fd407b
    Content-type: text
    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit
    
    
    --b4a9573f5eee9376fd19690bd02fd407b
    Content-Type: text; name="testfile.txt"
    Content-Transfer-Encoding:base64
     Content-Disposition: attachment; filename="testfile.txt"
    
    
    
    dmJLZXlEaXZpZGV2YktleUxCdXR0b24gJkgxIExlZ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5IDU3
    IDkga2V5DQp2YktleU51bXBhZDAgJkg2MCAwIGtleSANCnZiS2V5TnVtcGFkMSAmSDYxIDEga2V5
    IA0KdmJLZXlOdW1wYWQyICZINjIgMiBrZXkgDQp2YktleU51bXBhZDMgJkg2MyAzIGtleSANCnZi
    S2V5TnVtcGFkNCAmSDY0IDQga2V5IA0KdmJLZXlOdW1wYWQ1ICZINjUgNSBrZXkgDQp2YktleU51
    bXBhZDYgJkg2NiA2IGtleSANCnZiS2V5TnVtcGFkNyAmSDY3IDcga2V5IA0KdmJLZXlOdW1wYWQ4
    ICZINjggOCBrZXkgDQp2YktleU51bXBhZDkgJkg2OSA5IGtleSANCnZiS2V5TXVsdGlwbHkgJkg2
    QSBNVUxUSVBMSUNBVElPTiBTSUdOICgqKSBrZXkgDQp2YktleUFkZCAmSDZCIFBMVVMgU0lHTiAo
    Kykga2V5IA0KdmJLZXlTZXBhcmF0b3IgJkg2QyBFTlRFUiBrZXkgDQp2YktleVN1YnRyYWN0ICZI
    NkQgTUlOVVMgU0lHTiAolikga2V5IA0KdmJLZXlEZWNpbWFsICZINkUgREVDSU1BTCBQT0lOVCAo
    Likga2V5IA0KdmJLZXlEaXZpZGUgJkg2RiBESVZJU0lPTiBTSUdOICgvKSBrZXkgDQp2YktleUYx
    ICZINzAgRjEga2V5IA0KdmJLZXlGMiAmSDcxIEYyIGtleSANCnZiS2V5RjMgJkg3MiBGMyBrZXkg
    DQp2YktleUY0ICZINzMgRjQga2V5IA0KdmJLZXlGNSAmSDc0IEY1IGtleSANCnZiS2V5RjYgJkg3
    NSBGNiBrZXkgDQp2YktleUY3ICZINzYgRjcga2V5IA0KdmJLZXlGOCAmSDc3IEY4IGtleSANCnZi
    S2V5RjkgJkg3OCBGOSBrZXkgDQp2YktleUYxMCAmSDc5IEYxMCBrZXkgDQp2YktleUYxMSAmSDdB
    IEYxMSBrZXkgDQp2YktleUYxMiAmSDdCIEYxMiBrZXkgDQp2YktleUYxMyAmSDdDIEYxMyBrZXkg
    DQp2YktleUYxNCAmSDdEIEYxNCBrZXkgDQp2YktleUYxNSAmSDdFIEYxNSBrZXkgDQp2YktleUYx
    NiAmSDdGIEYxNiBrZXkgDQo=
    
    --b4a9573f5eee9376fd19690bd02fd407b--
    
    
    -- 
    This message has been scanned for viruses and
    dangerous content by MailScanner, and is
    believed to be clean.
    If you are sending the same attachment via email many times then you should upload the file once and save it locally on the server.
    that is the general idea, the content of the email is quite small, but the attachment is not

    i thought once i figured out enough php i would be able to process all the emails from one script, but i have a difficult time trying to work out why somthing does not work, unlike vb6 where i can see all kinds of stuff in the locals window in the IDE

    thanx for the link to file functions
    Last edited by westconn1; Dec 2nd, 2008 at 03:56 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width