无法使用wp_mail()和amazon-ses在电子邮件中发送附件



我添加了以下代码来使用wp_mail((函数发送附件。托管代码的Runcloud服务器配置有AmazonSES。在这种情况下,附件不会与邮件一起发送,相同的代码在带有飞轮的本地环境中完美运行。

代码-

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

您有两个问题,一个是正确配置wp_mail函数。

我建议您使用此插件并根据需要进行配置:https://es.wordpress.org/plugins/easy-wp-smtp/

另一个问题是发送附件。此线程可能会帮助您:如何在wordpress中发送带有附件的电子邮件?

最新更新