I have added the following code to send attachments using wp_mail() function. The Runcloud server on which the code is hosted is configured with Amazon SES. On that, the attachment is not sent with the mail, the same code runs perfectly on the local environment with Flywheel.
Code-
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 );