[resolved] wp_mail + attachment (2 posts)

  1. Peter_L
    Posted 3 years ago #


    I am building a contactpage, page-contact.php.
    I have something more complex in mind but as a test, I tried to add an attachment to wp_mail and it doesn't work. And that is my problem.

    The mail itself works fine but there simply isn't an attachment. I use a simple text document, test.txt, that is located in the root of my there folder.

    This is a simplified version of my code:

    $headers = 'From: My Name <myname@mydomain.com>' . "\r\n";
    $attachments = get_bloginfo('template_directory') . '/test.txt';
    wp_mail( 'myname@mydomain.com', 'testmail', 'This is a testmail', $headers, $attachments);

    Possible problems:
    - path to attachment file is wrong
    - $headers: content type is wrong
    - attachment file is too small...?
    - wrong setting in php.ini

    None of these possibilities I have an answer to.
    So here is my question: What am I doing wring or What could I be doing wrong?

  2. Peter_L
    Posted 3 years ago #

    I found the problem, the path to the file was wrong.

    I uploaded a new test file using the wordpress media manager. Path looks like this now:

    $attachments = array(WP_CONTENT_DIR . '/uploads/2012/02/test.txt');

Topic Closed

This topic has been closed to new replies.

About this Topic