Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Attachment Mail Not Working

    I'm trying to use this script to send an attached email-

    PHP Code:
    function mail_attachment($arr$mailto$from_mail$from_name$replyto$subject$message)
                                    {
                                        
    $uid md5(uniqid(time()));
                                        
    $name basename($file);
                                        
    $header "From: ".$from_name." <".$from_mail.">\r\n";
                                        
    $header .= "Reply-To: ".$replyto."\r\n";
                                        
    $header .= "MIME-Version: 1.0\r\n";
                                        
    $header .= "Content-Type: multipart/mixed\r\n boundary=\"".$uid."\"\r\n\r\n";
                                        
    $header .= "This is a multi-part message in MIME format.\r\n";
                                        
    $header .= "--".$uid."\r\n";
                                        
    $header .= "Content-type:text/html\r\n charset=utf-8\r\n";
                                        
    $header .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
                                        
    $header .= $message."\r\n\r\n";
                                        
                                        foreach(
    $arr as $arr2)
                                        {
                                            
    $file $arr2['tmp_name'];
                                            
    $file_size filesize($arr2['tmp_name']);
                                            
    $filename $arr2["name"];
                                            
    $handle fopen($file"r");
                                            
    $content fread($handle$file_size);
                                            
    fclose($handle);
                                            
    $content chunk_split(base64_encode($content));
                                            
    $header .= "--".$uid."\r\n";
                                            
    $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"// use different content types here
                                            
    $header .= "Content-Transfer-Encoding: base64\r\n";
                                            
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
                                            
    $header .= $content."\r\n\r\n";
                                        }
                                        
                                        
    $header .= "--".$uid."--";
                                        
                                        if (
    mail($mailto$subject""$header)) {
                                            echo 
    "mail send ... OK"// or use booleans here
                                        
    } else {
                                            echo 
    "mail send ... ERROR!";
                                        }
                                    } 
    But what I get is this-

    Content-Type: multipart/mixed

    boundary="0acc283a87c60187b4ea6f6d1c2f0636"




    This is a multi-part message in MIME format.

    --0acc283a87c60187b4ea6f6d1c2f0636

    Content-type:text/html

    charset=utf-8

    Content-Transfer-Encoding: 8bit



    <table><tr>
    <td>name:</td>
    <td>test</td>
    </tr><tr>
    <td>email:</td>
    <td>test</td>
    </tr><tr>
    <td>discipline:</td>
    <td>3-Dimensional</td>
    </tr><tr>
    <td>date:</td>
    <td>2012-04-17 10:39:01</td>
    </tr><tr>
    <td>ip:</td>
    <td>64.139.93.93</td>
    </tr></table>



    --0acc283a87c60187b4ea6f6d1c2f0636

    Content-Type: application/octet-stream; name="5.png"

    Content-Transfer-Encoding: base64

    Content-Disposition: attachment; filename="5.png"



    iVBORw0KGgoAAAANSUhEUgAAANcAAACcCAYAAADs4j4aAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz

    AAALEgAACxIB0t1+/AAAABR0RVh0Q3JlYXRpb24gVGltZQAzLzEvMTIfY+T1AAAAHHRFWHRTb2Z0

    d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M1cbXjNgAAIABJREFUeJztnXt8FNXd/z8zu4FsLmQhkIQQ
    ....
    Top bit should be html. Bottom should be an image. Any thoughts?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Is that how the actual content of the mail looks, or is that the complete mail received?
    I don't have time to crack open the rfc for this atm, but offhand it looks correct with the boundaries and the types. PEAR also has some extended packages to make mailing attachments easier.


  •  

    Posting Permissions

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