• Hello,

    When sending an email with a pdf attachement, the email went thru but not the attachment.

    I dumped the data object before it was sent to Sparkpost API and I could see the attachement like this : [{“name”:”document.pdf”,”type”:”application\/pdf”,”data”:”JVBERi0xLjQNJ…
    But the email I received did not contain it !

    I am currently using Sendgrid to send email and the attachment works with them for the same email.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor rajuru

    (@rajuru)

    @tii
    Can you give some example usages? Like how did you invoke the wp_mail?

    Thanks

    Thread Starter Tii

    (@tii)

    Here is the test code I was using :

    $to = "[email protected]";
    $headers = array();
    $attachments = array();
    $from = get_option('admin_email');
    $subject = sanitize_post($_POST['subject']);
    $headers[] = 'Cc: ' . $from;
    $content = sanitize_post($_POST['content']);
    $pdf_path = ABSPATH.'/pdf/document.pdf';
    $attachments[] = $pdf_path;
    if (wp_mail($to, $subject, $content, $headers, $attachments)) {
    	echo "SENT";
    }

    but, as I said, the attachment showed up in the json and, this code is working with the sendgird plugin so it seems to me like I attached it correctly…

    Plugin Contributor rajuru

    (@rajuru)

    Thanks for the snippet. What sparkpost mailer (smtp/http) are you using?

    Plugin Contributor rajuru

    (@rajuru)

    I see you said JSON, so I assume you are using HTTP mailer. Is that right?

    Thread Starter Tii

    (@tii)

    http

    Plugin Contributor rajuru

    (@rajuru)

    @tii
    I just tested attachment with HTTP Mailer and seems it’s working.

    `
    $pdf_path = dirname(__FILE__) . ‘/hello.txt’;
    $headers = array();

    $attachments= array($pdf_path);

    $result = wp_mail($recipient,
    $subject,
    $body,
    $headers,
    $attachments
    );`

    I got the email with attachment delivered correctly.

    Can you post the Request Body (shown in verbose log) so that I can inspect? Please mask any private data.

    Also, are you using any Template (Specified a template ID in the plugin settings)?

    Thread Starter Tii

    (@tii)

    Your remark was good, I removed the tmeplate and the attachment went thru !

    why is that and how can I use the template with an attachment ?

    • This reply was modified 8 years, 1 month ago by Tii.
    Plugin Contributor rajuru

    (@rajuru)

    You can find more info about template and attachment here.

    You can also specify template ID in the settings but when you wanna send attachments, you can use plugin hooks to remove the template just before calling wp_mail (and remove the filter after wp_mail).

    Thread Starter Tii

    (@tii)

    well, I want to send email with a template and an attachment, otherwise, I’m not interested as I already have a working solution with Sendgrid.

    I’m not gonna hack my way to use Sparkpost. I understand that it’s a Sparkpost problem but, I think the plugin should inform it’s users that you cannot send an attachment with a template !

    Plugin Contributor rajuru

    (@rajuru)

    Sorry to know it’s not working as you expected. And unfortunately, it’s not a drop-in replacement of other plugins too.

    Thanks for suggestion about clarifying the issue. I’ve just logged in issue https://github.com/SparkPost/wordpress-sparkpost/issues/96.

    Thanks

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Attachments not working’ is closed to new replies.