2016-03-23 31 views
0

私はwordpress 'wp_mail関数を使用して添付ファイル付きのメールを送信したいと思います。添付ファイル付きのwp_mailの送信方法(可変ファイルパス)

この機能では電子メールを送信するのにうまく動作しますが、メールをチェックするときに添付ファイルはありません。

function dd_send_email(){ 

    $dd_path = $_POST['upload_image']; 
    // echo $dd_path; 

    $email_sent = false; 

    // get email template data 
    $email_template_object = dd_get_current_options(); 


    // if email template data was found 
    if (!empty($email_template_object)): 

     // setup wp_mail headers 
     $wp_mail_headers = array('Content-Type: text/html; charset=UTF-8'); 
     $mail_attachment = $dd_path; 

     // use up_mail to send email 
     $email_sent = wp_mail(array('[email protected]') , $email_template_object['dd_emne_forhaandsbestilling'], $email_template_object['dd_email_text_forhaandsbestilling'], $wp_mail_headers, $mail_attachment); 

    endif; 

    return $email_sent; 

} 

変数$dd_path(のようなもの:http://localhost/norskeanalyser/wp-content/uploads/Testanalyse-2.pdfは)私は別の関数内のメディアアップローダーからアップロードするか、ファイルのパスが含まれています。

ありがとうございました!

答えて

0

私は自分で答えを見つけました。 wp_mailはこの/uploads/2016/03/example.jpgのようなファイルパスを必要とするため、このようなパスにURLを変換する必要があります。

私は、次の手順を実行してachiveこれをしなかったし、私はあなたとそれを共有することができます考えた:

// change url to path 
    $dd_url = $_POST['upload_image']; 
    $dd_path = parse_url($dd_url); 

    // cut the path to right directory 
    $array = explode("/norskeanalyser/wp-content", $dd_path['path']); 
    unset($array[0]); 
    $text = implode("/", $array); 

をして、私は$mail_attachment$textを保存しなかったし、上記のようなwp_mailでそれを呼びました。

関連する問題