wp_mail 发送带有编码字符串作为附件的电子邮件

wp_mail send email with encoded string as attachment

我应该怎么做?基本上我有下面的代码,$pdf 是 pdf 文件的 base64 编码字符串

add_action('wp_ajax_email_portfolio', 'ajax_email_portfolio');

function ajax_email_portfolio()
{

    check_ajax_referer('ajax-email-portfolio', 'security');
    $pdf = $_POST['pdf'];
    $email_address = $_POST['email_address'];


    #NOTIFY USER
    $subject = 'Portfolio from somewhere';
    $headers = 'From: Someone <no-reply@somewhere.com>';
    $email_body = 'Portfolio from Someone';
    $destination_email = $email_address;

    wp_mail($destination_email, $subject, $email_body, $headers);

    echo json_encode(array('success' => true,'pdf'=> $pdf,'email_address'=>$email_address));

    die();
}

任何帮助将不胜感激!

这是我的代码,它适用于 gmail,但如果发送到 outlook,它会打印出 `$current_user = wp_get_current_user();

$pdf = $_POST['pdf'];
$email_address = $_POST['email_address'];
$eol = PHP_EOL;
$uid = md5(uniqid(time()));
$destination_email = $email_address;
$attachment_content = chunk_split($pdf);
$filename = "portfolio.pdf";
#NOTIFY USER
$subject = 'Portfolio from xxxxxx';
$headers = 'From: '. $current_user->user_firstname . ' <' . $current_user->user_email . '> '. $eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"";
$email_body = "--".$uid.$eol;
$email_body .= "Content-Transfer-Encoding: 7bit".$eol;
$email_body .= "Portfolio from xxxxxx".$eol;
// attachment
$email_body .= "--".$uid.$eol;
$email_body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$email_body .= "Content-Transfer-Encoding: base64".$eol;
$email_body .= "Content-Disposition: attachment".$eol;
$email_body .= $attachment_content.$eol;
$email_body .= "--".$uid."--";


wp_mail($destination_email, $subject, $email_body, $headers);`