Using wp_mail with attachments but no attachments received

The $attachment argument for wp_mail takes a file (or array of files) – but the file path has to be fully specified. For example:

<?php
   $attachments = array(WP_CONTENT_DIR . '/uploads/file_to_attach.zip');
   $headers="From: My Name <[email protected]>" . "\r\n";
   wp_mail('[email protected]', 'subject', 'message', $headers, $attachments);
?>

(see Codex). It seems that your $_POST['file'] is probably not specifying the full path.

The attachment has to a file path, not an url. The following worked for me:

$to = $_POST['to'];
$from = $_POST['from']; 
$name = get_bloginfo('name');

$headers="From: My Name <[email protected]>" . "\r\n";

$subject="Send to Kindle";

$msg = 'Yay! Your book has <a href="http://yahoo.com">arrived</a>';

$mail_attachment = array(WP_CONTENT_DIR . '/uploads/2012/03/image.png');   

wp_mail($to, $subject, $msg, $headers, $mail_attachment);

Note: I changed the headers attribute too. I’m not entirely sure what you’re example was trying to do, but it meant the message of the email was not visible on some email clients.

Leave a Comment