首页 > 解决方案 > 由于端点不安全,带有 mailto 操作的 HTML 表单不起作用

问题描述

我正在尝试通过直接在模板块上键入 html 代码来制作 wordpress 表单(这与所需的视觉设计完全匹配)并且它不起作用。我在 chrome 控制台上收到此错误消息:

混合内容:“https://protegetumarcaonline.com/”上的页面是通过安全连接加载的,但包含针对不安全端点“mailto:proyectosonline@isern.com”的表单。该端点应通过安全连接提供。

https://photos.app.goo.gl/687cUavnacTQ94fF7

这是表单代码:

<form action="mailto:proyectosonline@isern.com" method="get" enctype="text/plain">
        
                            SOBRE TI <br><br>
                            Nombre*<br>
                            <input style="width:100%;" type="text" name="nombre" required="" class="czr-focusable">
                            Email*<br>
                            <input style="width:100%;" type="text" name="email" required="" class="czr-focusable">
                            ¿Tienes web?<br>
                            <input style="width:100%;" type="text" name="web" class="czr-focusable">
                       
                            Marca*
                            <input style="width:100%;" type="text" name="marca" required="" class="czr-focusable">
                            Productos y/o Servicios de interés*
                            <textarea style="width: 100%; margin-top: 0px; margin-bottom: 0px; height: 82px;" name="mensaje" required="" class="czr-focusable">                                </textarea>
                            <input type="checkbox" name="Facebook"> Facebook<br>
                            <input type="checkbox" name="Instagram"> Instagram<br>
                            <input type="checkbox" name="Twitter"> Twitter<br>
                            <input type="checkbox" name="Web propia"> Web propia<br>
                            <input type="checkbox" name="Amazon"> Amazon<br>
                            <input type="checkbox" name="Alibaba"> Alibaba<br>
                            <input type="checkbox" name="Otras"> Otras<br>
                       
                
                            <input type="checkbox" required="" name="politica"> Acepto la política de privacidad*<br>
                            <input type="checkbox" name="comunicaciones"> Acepto recibir comunicaciones comerciales e informativas<br><br>
                            <input type="image" src="wp-content/uploads/2020/11/icono-ENVIAR.png" value="Enviar" name="enviar" alt="Enviar" width="110 style=" border:="" none;"="">

我也尝试使用方法 post 并获得相同的结果。该网站是:https ://protegetumarcaonline.com/

我能做什么?

非常感谢,米格尔·吉斯伯特

标签: wordpressformsmailtomixed-contentinsecure-connection

解决方案


无法通过安全连接使用“mailto:”,因为 mailto: 打开了一个应用程序来发送邮件。可能使用或不使用安全协议 (TLS) 的应用程序。

解决此问题的一种方法是使用调用 PHP 脚本发送邮件的 POST 表单。所以你的 HTML 看起来像这样:

<form method="post" action="/wp-content/php_scripts/send_mail.php">
    SOBRE TI <br><br>
    Nombre*<br>
    <input style="width:100%;" type="text" name="nombre" required="" class="czr-focusable">
    Email*<br>
    <input style="width:100%;" type="text" name="email" required="" class="czr-focusable">
    ¿Tienes web?<br>
    <input style="width:100%;" type="text" name="web" class="czr-focusable">        
    Marca*
            <input style="width:100%;" type="text" name="marca" required="" class="czr-focusable">
    Productos y/o Servicios de interés*
    <textarea style="width: 100%; margin-top: 0px; margin-bottom: 0px; height: 82px;" name="mensaje" required="" class="czr-focusable">                                </textarea>
    <input type="checkbox" name="Facebook"> Facebook<br>
    <input type="checkbox" name="Instagram"> Instagram<br>
    <input type="checkbox" name="Twitter"> Twitter<br>
    [...]
    <input type="submit">
</form>

还有你的 PHP 文件 send_mail.php

<?php
/**
 * Filter the mail content type.
 */
function wpdocs_set_html_mail_content_type() {
    return 'text/html';
}
add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );

$message = '<p>Nombre:' . $_POST['nombre'] . '</p><p>Email:' . $_POST['email'] .'</p><p>...</p>';
$result = wp_mail('proyectosonline@isern.com', 'New mail', $message);
if ($result ) {
    // Do something here
}
// Reset content-type to avoid conflicts -- https://core.trac.wordpress.org/ticket/23578
remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
?>

wp_mail 文档:https ://developer.wordpress.org/reference/functions/wp_mail/

wp_mail_content_type:https ://developer.wordpress.org/reference/hooks/wp_mail_content_type/


推荐阅读