Site icon Hip-Hop Website Design and Development

How to do string attachment with wp_mail

I’m using a gift card plugin for my woocommerce shop and I would like to add a generated pdf file to allow customers to download the gift card as a pdf.

The idea is to use TCpdf or Fpdf to generate the pdf and output it as a string.

// Close and output PDF document
// This method has several options, check the source code documentation for more information.


echo $pdf->Output('S');

The problem is to get this file as an attachment with wp_mail. Right now, I have this code from the plugin, and i don’t know how to call the pdf :

/**
 * Hooks before the email is sent
 *
 * @since 2.1
 */
do_action( 'kodiak_email_send_before', $this );

$subject = $this->parse_tags( $subject );
$message = $this->parse_tags( $message );
$message = $this->build_email( $message );

$attachments = ??;


$sent = wp_mail( $to, $subject, $message, $this->get_headers(), $attachments );
$log_errors = apply_filters( 'kodiak_log_email_errors', true, $to, $subject, $message );

if( ! $sent && true === $log_errors ) {
  if ( is_array( $to ) ) {
    $to = implode( ',', $to );
  }

  $log_message = sprintf(
    __( "Email from Gift Cards failed to send.nSend time: %snTo: %snSubject: %snn", 'kodiak-giftcards' ),
    date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ),
    $to,
    $subject
  );
}

Is someone can help me with this ?

Thank you for the answer !