2017-03-02 6 views
0

Wie soll ich das machen? Basicly habe ich den Code unten, und der $ pdf ist der codierte base64 String der pdf-Dateiwp_mail sende email mit codierter string als anhang

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(); 
} 

Jede mögliche Hilfe geschätzt wird!

+0

Was macht Ihre 'add_action' Funktion? – wahwahwah

+0

@wahwahwah es registriert diese Funktion, das ist es – kwokkaki

+0

baue einfach deine html-Pakete (mit Kopfzeilen) wie du ohne die Komplikation auskommen würdest .... wenn * die Kodierung * ein Problem ist, dann denke ich, dass du deine Frage ändern musst, – wahwahwah

Antwort

0

Hier ist mein Code, es funktioniert gut für Google Mail, aber wenn Outlook gesendet wird, druckt es die $ 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);` 
Verwandte Themen