Welcome Guest, Not a member yet? Register   Sign In
Problems sending mail with attachment
#1

[eluser]Armchair Samurai[/eluser]
I'm having a problem sending emails with attachments:

There is a contact form which allows users to submit an email with an attachment. Everything seems to work fine, but when the email is received, it is malformed, with no trace of the original message and the base64 encoded attachment displayed. Here is the relevant code:

Code:
$this->load->library('upload');

$this->upload->initialize(array(
    'upload_path'    => 'path/to/temp/dir/',
    'allowed_types'    => 'txt|rtf|doc|docx|word',
    'max_size'    => 200
));
        
if ( ! $this->upload->do_upload('resume'))
{
    show_error($this->upload->display_errors());
    exit;
}
else
{
    $this->load->library('email');
            
    $file    = $this->upload->data();
    $name    = $this->input->post('name');
    $email   = $this->input->post('email');
            
    $this->load->vars(array(
        'location'   => $this->input->post('location'),
        'arrival'    => $this->input->post('arrival'),
        'name'       => $name,
        'visa'       => $this->input->post('visa'),
        'email'      => $email,
        'job'        => $this->input->post('job'),
        'now'        => date('r')
    ));
    $this->email->from('[email protected]');
    $this->email->reply_to($email);
    $this->email->to('[email protected]');
    $this->email->subject('Employment inquiry from '.$name);
    $this->email->message($this->load->view('mail', NULL, TRUE));
    $this->email->attach($file['full_path']);
        
    $sent    = $this->email->send();
    
    unlink($file['full_path']);
    
    if ( ! $sent)
    {
        show_error('Unable to send email - operation aborted.');
        exit;
    }
    else
    {
        redirect('apply/thank_you', 'Location');
    }
}

The mail arrives with no problem and the headers seem to be normal, but the body always looks something like this:

Code:
This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ATC_4c9f3af4ae704
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Mime-Version: 1.0
Content-Transfer-Encoding: BASE64

TG9jYXRpb246IEluIEphcGFuCk5hbWU6IFJvYmVydApWaXNhOiBTcG91c2UgVmlzYQpFbWFpbDog
cm9iQG9zYWthLWRlc2lnbi5jb20KSW50ZXJlc3RlZCBwb3NpdGlvbjogRnJlbmNoIEluc3RydWN0
b3IKLS0tClNlcnZlciB0aW1lOiBTdW4sIDI2IFNlcCAyMDEwIDIxOjIyOjEyICswOTAwCgoKLS1C
X0FUQ180YzlmM2FmNGFlNzA0CkNvbnRlbnQtdHlwZTogYXBwbGljYXRpb24vcGRmOyBuYW1lPSJy
ZXBsYWNlbWVudC1mbG93Y2hhcnQucGRmIgpDb250ZW50LURpc3Bvc2l0aW9uOiBhdHRhY2htZW50
OwpDb250ZW50LVRyYW5zZmVyLUVuY29kaW5nOiBiYXNlNjQKCkpWQkVSaTB4TGpNS0pjVGw4dVhy
cC9PZzBNVEdDalFnTUNCdlltb0tQRHdnTDB4bGJtZDBhQ0ExSURBZ1VpQXZSbWxzZEdWeUlDOUcN
...

As you can see, the text from the email is missing and the content boundary appears to be malformed. If I send the mail without the attachment, everything comes through with no problems. I have also checked to see if the file is being uploaded correctly and it appears to be normal.

I'm using CI 1.7.2 and PHP 5.2.14. Does anyone have any ideas?
#2

[eluser]umefarooq[/eluser]
try to debug you sent mail just put

Code:
$this->email->print_debugger();

also check your mail mailtype its going as text set it to html and check the result well debugger will help you more
#3

[eluser]InsiteFX[/eluser]
show your mail view code!

InsiteFX
#4

[eluser]Armchair Samurai[/eluser]
[quote author="umefarooq" date="1285581425"]try to debug you sent mail just put

Code:
$this->email->print_debugger();
[/quote]

Ah... thanks for reminding me - I always seem to forget that function exists. It does get really weird though... print_debugger() gave me a relatively normal result:

Code:
Your message has been successfully sent using the following protocol: mail

From:
Return-Path:
Reply-To: "[email protected]"
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="B_ATC_4ca1acb0d3a9d"

This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ATC_4ca1acb0d3a9d
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Employment_inquiry_from_John_Doe?=
Location: In Japan

Name: John Doe

Visa: Specialist in Humanities

Email: [email protected]

Interested position: HR

---
Server time: Tue, 28 Sep 2010 17:52:00 +0900


--B_ATC_4ca1acb0d3a9d
Content-type: application/x-unknown-content-type; name="wiggum.docx"
Content-Disposition: attachment;
Content-Transfer-Encoding: base64

UEsDBBQABgAIAAAAIQBrp+WywAEAAE8HAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC
...

However, when the mail arrives at the destination, one of two things happen:

1) Gmail re-encodes everything from the "Location: In Japan" line in base64. Very weird.

2) Hotmail receives the message as is, but does not recognize the attachment - everything is displayed as plain text.

I must admit I'm stumped - anyone have any idea what's going on?




Theme © iAndrew 2016 - Forum software by © MyBB