为了账号安全,请及时绑定邮箱和手机立即绑定

Wordpress 将 XML 文件发送到电子邮件

Wordpress 将 XML 文件发送到电子邮件

PHP
慕尼黑8549860 2023-04-15 10:43:12
我正在尝试实现此结果:我正在使用联系表 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 直接发送到电子邮件地址?
查看完整描述

1 回答

?
宝慕林4294392

TA贡献2021条经验 获得超8个赞

生成文件后,函数可以使用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 = "sendto@example.com";

   $subject = "The subject";

   $body = "The email body content";

   $headers = "From: My Name <myname@example.com>" . "\r\n";


   $attachments = array( "cf7outputtest.xml" );


   wp_mail( $to, $subject, $body, $headers, $attachments );

}


查看完整回答
反对 回复 2023-04-15
  • 1 回答
  • 0 关注
  • 103 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信