2017-03-02 82 views
0

我應該怎麼做?基本上我有下面的代碼,$ pdf是pdf文件的base64編碼字符串wp_mail發送帶有編碼字符串的電子郵件作爲附件

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 <[email protected]>'; 
    $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(); 
} 

任何幫助將不勝感激!

+0

你的'add_action'函數在做什麼? – wahwahwah

+0

@wahwahwah它正在註冊這個功能,就是它 – kwokkaki

+0

只是建立你的html數據包(帶頭)你怎麼沒有併發症....如果*編碼*是一個問題,那麼我認爲你需要改變你的問題, – wahwahwah

回答

0

這裏是我的代碼,它可以很好地用於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);` 
相關問題