Wordpress wp_mail会在发送电子邮件后临时保存附件并删除

时间:2016-09-29 19:19:10

标签: php wordpress

使用wp_mail()处理电子邮件和附件。如果上传的附件是临时存储的,并且在发送电子邮件后删除了,我会更喜欢。目前,上传/附件已保存在服务器上。如何防止这种情况?

 appExcel.Visible = true;
            classeur = appExcel.Workbooks.Open(DB_Path, 0, false, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            appExcel.Visible = false;

1 个答案:

答案 0 :(得分:1)

您是否关心它是否成功发送?

如果没有,那就这样做:

if( $wp_mail_return ) {
    echo 'Mail send';
} else {
    echo 'Failed';
}

// Loops over the attachments (per your array), and removes the file
foreach ( (array)$attachments AS $file ) {
    unlink( $file );
}

如果您只是想成功发送,请将其移至if条件中:

if( $wp_mail_return ) {
    echo 'Mail send';
    // Loops over the attachments (per your array), and removes the file
    foreach ( (array)$attachments AS $file ) {
        unlink( $file );
    }
} else {
    echo 'Failed';
}