簡體   English   中英

無法使用 wp_mail() 和 amazon ses 在 email 中發送附件

[英]Unable to send attachment in email using wp_mail() and amazon ses

我添加了以下代碼以使用 wp_mail() function 發送附件。托管代碼的 Runcloud 服務器配置有 Amazon SES。 在那一點上,附件不會隨郵件一起發送,相同的代碼可以在帶有 Flywheel 的本地環境中完美運行。

代碼-

add_action(
            'phpmailer_init', function( $phpmailer ) use ( $connection_data ) {
                $phpmailer->IsSMTP();
                $phpmailer->Host = smtp.gmail.com;
                $phpmailer->Port = 587;
                $phpmailer->Username = //username;
                $phpmailer->Password = //password;
                $phpmailer->SMTPAuth = true;
                $phpmailer->SMTPSecure = 'tls';
                $phpmailer->Timeout = 30;
            }
        );

add_filter(
            'wp_mail_content_type', function() {
                return 'text/html';
            }
        );

$file = 'https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg';
$file_name = basename( $file );
$file_name = ! strrpos( $file_name, '.' ) ? $file_name . '.txt' : $file_name;
$content = @file_get_contents( trim( $file ) ) ? wp_remote_get( trim( $file ) ) : $file;
file_put_contents( $file_name, $content['body'] );
$attachments[] = $file_name;

$headers[] = 'From: //Name <//email>';
$send_email = wp_mail( wp_get_current_user()->user_email, 'STMP connection validation', 'STMP connection validation.', $headers, $attachments );

你有 2 個問題,一個是正確配置 wp_mail function。

我建議您使用此插件並根據需要進行配置: https://es.wordpress.org/plugins/easy-wp-smtp/

另一個問題是發送附件。 這個帖子可能對你有幫助: How to send an email with attachment in wordpress?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM