Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Sending file in a EMAIL is malformed
  • Currently, our system have email function and the email includes sending a file such as pdf or image. It works fine but I when I transfer to MAILGUN, email is sent but files are malformed. Instead of a file is sent, the email only sent bunch of code such as the following below.

    --B1_ae88df0c85c980c0c798ce5362416df2
    Content-Type: text/plain; charset="utf-8"
    Content-Transfer-Encoding: 8bit

    I want to use mailgun because number of users are increasing, I already ask a help from mailgun support but they just said they are not familiar with FUELPHP so that's why I'm trying to ask for help here.
  • We use the standard Mailgun SDK installed by composer. Our mailgun driver can be found here: https://github.com/fuel/email/blob/1.8/develop/classes/email/driver/mailgun.php

    I double checked it against Mailgun's SDK docs, and as far as I can see, it does what it should.

    That "bunch of code" is a multipart-mime header. I don't know where you check the result of the email, perhaps you use a client that doesn't support multipart-mime emails?

  • Thanks for your response Mr. Verton,

    I install Mailgun by composer.

    That "bunch of code" is a multipart-mime header. I don't know where you check the result of the email, perhaps you use a client that doesn't support multipart-mime emails?
    ~ You mean it depends on the email? But before I used mailgun, I'm using the default email driver of fuelphp but the message and files (pdf) can be sent. But when transferring to mailgun, message is sent but files (pdf) are converted to bunch of codes.
  • And my question was: where do you see that? in your email client? Which client? To me that looks like a multipart-mime header, and that is perfectly normal in an email with attachments. It is the task of the email client to convert that back to attachments.

    There is nothing the Fuel driver does, other than pass the email information on to the Mailgun SDK. The conversion of a file to something that can be transmitted in an email happens in Mailgun:

            // Standard required fields
            $post_data = array(
                'from'    => $this->config['from']['email'],
                'to'      => static::format_addresses($this->to),
                'subject' => $this->subject,
                'html'    => $message['body'],
            );

            // Optionally cc, bcc and alt_body
            $this->cc and $post_data['cc'] = static::format_addresses($this->cc);
            $this->bcc and $post_data['bcc'] = static::format_addresses($this->bcc);
            $this->alt_body and $post_data['text'] = $this->alt_body;

            // Mailgun's "arbitrary headers" are h: prefixed
            foreach ($headers as $name => $value)
            {
                $post_data["h:{$name}"] = $value;
            }

            // Add the attachments
            $post_body = array(
                'attachment' => array(),
                'inline' => array(),
            );

            foreach ($this->attachments['attachment'] as $cid => $file)
            {
                $post_body['attachment'][] = array('filePath' => $file['file'][0], 'remoteName' => $file['file'][1]);
            }

            foreach ($this->attachments['inline'] as $cid => $file)
            {
                $post_body['inline'][] = array('filePath' => $file['file'][0], 'remoteName' => substr($cid, 4));
            }

            // And send the message out
            $mailgun->sendMessage($this->config['mailgun']['domain'], $post_data, $post_body);

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion