6

Now I can send an email without attachment :

wp_mail( $to, $subject, $message, $headers);

But how can I send an email with attachment?

fms
  • 2,147
  • 4
  • 18
  • 16

3 Answers3

8
 <?php wp_mail( $to, $subject, $message, $headers, $attachments ); ?> 

http://codex.wordpress.org/Function_Reference/wp_mail

zod
  • 12,092
  • 24
  • 70
  • 106
  • how can i add html content? – Sarower Jahan Jan 25 '18 at 01:25
  • 1
    as per documentation The default content type is ‘text/plain’ which does not allow using HTML. You can set the content type of the email either by using the ‘wp_mail_content_type‘ filter ( see example below), or by including a header like “Content-type: text/html”. Be careful to reset ‘wp_mail_content_type’ back to ‘text/plain’ after you send your message, though, because failing to do so could lead to unexpected problems with e-mails from WP or plugins/themes. – zod Jan 25 '18 at 23:05
7

Refer below e.g.

$attachments = array(WP_CONTENT_DIR . '/uploads/file_to_attach.zip');
$headers = 'From: My Name <myname@mydomain.com>' . "\r\n";
wp_mail('test@test.com', 'subject', 'message', $headers, $attachments);
sandip patil
  • 638
  • 4
  • 8
0
add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components' );

function mycustom_wpcf7_mail_components( $components ) {
    $components['attachments'][] = 'full path of your PDF file';

    return $components;
}
Ankur
  • 5,086
  • 19
  • 37
  • 62