Skip to navigation
Send an attachment email file with wordpress
31.10.19
function bwc_send_email($coupon_id) { $pdf = bwc_create_pdf($coupon_id); $_path = tempnam(sys_get_temp_dir(), "{$coupon_id}_"); rename($_path, $_path .= '.pdf'); file_put_contents( $_path, $pdf ); $subject = ! empty( get_option( 'bwc_subject' ) ) ? get_option( 'bwc_subject' ) : ''; $message = ! empty( get_option( 'bwc_email_message' ) ) ? get_option( 'bwc_email_message' ) : esc_html__( 'Please download the PDF', "BWC_translate" ); $mail_settings = ! empty( get_option( 'woocommerce_email_from_address' ) ) ? get_option( 'woocommerce_email_from_address' ) : get_bloginfo( 'admin_email' ); $from_settings = ! empty( get_option( 'woocommerce_email_from_name' ) ) ? get_option( 'woocommerce_email_from_name' ) : get_bloginfo( 'name' ); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= "Content-Type: text/html\n"; $headers = 'From: ' . $from_settings . ' <' . $mail_settings . '>' . "\r\n" . 'Reply-To: ' . $mail_settings . '' . "\r\n"; $r = wp_mail( 'veto@myridia.com', $subject, $message, $headers, [$_path]); unlink($_path); return 'ok'; }
https://www.php.net/manual/en/function.tempnam.php
Reply
Anonymous
Information Epoch 1732616745
Use lower case and keep it short.
Home
Notebook
Contact us