【问题标题】:how to get image url and send mail before submiting in custom form using wordpress?如何在使用 wordpress 以自定义表单提交之前获取图像 url 并发送邮件?
【发布时间】:2017-03-07 01:04:39
【问题描述】:

我在我的 Wordpress 主题中使用自定义表单 这是我的表格

HTML

<form accept-charset = "UTF-8" action = "https://forexmplesecondsite.com/get_form_data" method = "POST" target = "_blank" enctype="multipart/form-data">
    <label for="customer-name"> your name *</label>
    <input type="text" id="customer-name" name="customer-name" />
    <label for="company-name"> your company name *</label>
    <input type="text" id="company-name" name="company-name" />
    <input type="file" name="customer-logo" />
    <input type="submit" value="upload" id="upload-form">
</form>

jQuery

jQuery(document).ready(function ($) {
    $("#upload-form").click(function(){
    <?php
    $to = 'mymail@email.com';
    $subject = "my mail subject";
    $message = "please check logo attachment";
    $headers = array(
        ‘From: My Name <myname@example.com>;',
        'BCC: My Other Name <myothername@example.com>;',
    );
    $attachments=$_FILES['customer-logo']['tmp_name'];
    wp_mail( $to, $subject, $message, $headers , $attachments );
    ?>
    });
});

当有人点击提交时,表单重定向到其他网站,我收到了邮件,但我看不到任何附件。

【问题讨论】:

  • 你是 php 新手,我可以看到 :)
  • 您需要处理上传的文件(move_uploaded_file( $tmpname, $target ))并使用$target作为附件

标签: php jquery wordpress forms email


【解决方案1】:

更改$attachments=array($_FILES['customer-logo']['tmp_name']);,如果这不起作用,请将文件保存到目录并改为引用该目录+文件

编辑: 从我所见,您正在尝试在 js 点击事件上触发 php,这是不可能的,最好使用简单的表单或更复杂的 ajax 请求

【讨论】:

  • 我正在尝试这个函数 wp_handle_upload();但我无法理解它的工作原理以及我在代码中的实际使用方式
  • 您阅读文档了吗?
  • 以及如何在提交表单之前保存图像
  • 使用ajax和formData上传文件
猜你喜欢
  • 2016-11-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-20
  • 1970-01-01
  • 1970-01-01
  • 2015-07-30
  • 2017-04-19
  • 2020-04-23
相关资源
最近更新 更多