我正在尝试实现这个结果。我使用的是联系表格7,我希望当你点击 "提交 "时,你不会收到纯文本的电子邮件,而是一个包含所有信息的.xml文件。作为xml文件的一个变通方法,我使用了这个函数。
add_action( 'wpcf7_before_send_mail', 'CF7_pre_send' );
function CF7_pre_send($cf7) {
$output = "";
$output .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>Name: " . $_POST['your-name'];
$output .= "Email: " . $_POST['your-email'];
$output .= "Message: " . $_POST['your-message'];
file_put_contents("cf7outputtest.xml", $output);
}
这样就能生成xml文件,但我只能把它保存在wordpress目录下,或者保存在一个特定的路径中。有没有一种方法或变通的办法,可以直接把这个xml文件发到电子邮件地址?
先谢谢你了。
卢卡
在生成文件后,函数可以使用 wp_mail
职能。
add_action( 'wpcf7_before_send_mail', 'CF7_pre_send' );
function CF7_pre_send($cf7) {
$output = "";
$output .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>Name: " . $_POST['your-name'];
$output .= "Email: " . $_POST['your-email'];
$output .= "Message: " . $_POST['your-message'];
file_put_contents( "cf7outputtest.xml", $output);
// then send email
$to = "[email protected]";
$subject = "The subject";
$body = "The email body content";
$headers = "From: My Name <[email protected]>" . "\r\n";
$attachments = array( "cf7outputtest.xml" );
wp_mail( $to, $subject, $body, $headers, $attachments );
}