if(isset($input->csvrequest)){
$mailsubject= $input->mailsubject;
$mailbody= $input->mailbody;
$mailto= $input->mailto;
$to = $mailto;
$mail_subject = $mailsubject;
$mail_message = $mailbody;
$headers = "From: Test <support@test.com>\r\n";
$headers .= "Reply-To: support@test.com\r\n";
$headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .= "X-Priority: 0\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=win-1251\r\n";
wp_mail($to, $mail_subject, $mail_message, $headers);
add_filter('wp_mail_content_type', create_function('', 'return "text/html"; '));
$arr["error"] = "Email Sent";
}
因此,此代码正在为我发送邮件。其实我想把这封邮件的附件发送给用户。(例如:file.csv)
答案 0 :(得分:0)
假设您已在 wordpress 媒体库中上传了“file.csv”。 现在,设置附件变量并传递给 wp 邮件功能,就是这样。 附件已开始发送。
$mail_attachment = array(WP_CONTENT_DIR . '/uploads/2021/03/file.csv');
wp_mail($to, $mail_subject, $mail_message, $headers, $mail_attachment);