联系人字段不起作用

Contact Field doesn't work

我突然发现我的联系人字段不起作用。这意味着我很可能在去年丢失了很多电子邮件......糟糕。

你能帮我看看哪里出了问题吗?

我在一年前测试时 100% 有效,但也许代码或浏览器设置中的某些内容已更改。

我查看了我的电子邮件中的垃圾邮件,那里什么也没有。

它在 Wordpress 中,我为此制作了一个插件。

<?php
/*
    Template Name:Haugsdalen_kontakt
*/
?>
<?php get_header(); ?>

<div id="left" class="eleven columns" >
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
        <div class="post" id="post-<?php the_ID(); ?>">
        <?PHP haugsdalen_kontaktplugin(); ?>    

        </div>
    <?php endwhile; endif; ?>   
</div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

抱歉,如果语言难以理解,但我想无论如何您只会查看代码。

<?php

/**
 * Plugin Name: Haugsdalen Skisenter Kontaktskjema
 * Description: Kontaktskjema for Haugsdalen Skisenter
 * Version: 1.0
 * Author: Ole Andreas Vekve
 * License: GPL2

    Copyright 2013  KANDIDATNUMMER 902

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as 
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

function test_input_kontakt($data)
{
     $data = trim($data);
     $data = stripslashes($data);
     $data = htmlspecialchars($data);
     return $data;
}

function haugsdalen_kontaktplugin () {
    function haugsdalen_kontakt_header () {
    echo ('<link rel="stylesheet" type="text/css" href="'.plugin_dir_url( __FILE__ ).'haugsdalen-kontakt.css">');   
    }

    $from = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $to = 'ole.andreas.vekve@gmail.com'; 
    $subject = 'Ny melding fra Haugsdalen Skisenter';

    $body = "Ny melding fra Haugsdalen Skisenter:\n Fra: $name\n E-post: $email\n Melding:\n $message";

    echo ('<div id="kontakthead">');            
    if ($_POST['submit']) {              
        if (mail ($to, $subject, $body, $from)) { 
        echo '<p>Din melding har blitt sendt!</p>';
    } else { 
        echo '<p>Noe gikk galt. Vennligst prøv igjen.</p>'; 
    } 
    } 
    echo ('<form method="post" action="http://haugsdalen.com/kontakt/">
    <h2>Kontakt</h2>   
    <label>Navn</label>
    <input name="from" placeholder="Ditt navn">

    <label>E-post</label>
    <input name="email" type="email" placeholder="Din e-post">

    <label>Melding</label>
    <textarea name="message" placeholder="Din melding..."></textarea>

    <input id="submit" name="submit" type="submit" value="Send inn"></form><br/>
    <h3><strong>Kontaktinformasjon:</strong></h3>
    Tlf: 73 85 46 05<br/>
    E-post: ole.andreas.vekve@gmail.com<br/>
    </div>');
}
?>

if (mail ($to, $subject, $body, $from)) 中的 $from 变量是 header 部分,邮件将其用作默认值 From:,这又取自 $from = $_POST['name']; 是 "name"。邮件正在读取 "From:" 作为名称。它需要是一个电子邮件地址。

因此,许多电子邮件客户端会将其视为垃圾邮件,或完全丢弃。

邮件是 reading/interpreting 它是 John@inexistant_user_on_yourserver.xxx 因此回落到 xxx@your_hosting_provider_mail.xxx 作为 "From:" 而不是 john@his_email_service.xxx

您需要将该变量更改为 $email,以便您的代码现在显示为

if (mail ($to, $subject, $body, $email))

有关这方面的更多信息,请阅读手册:

因此,您可以添加:

$header = "From: ". $from . " <" . $email . ">\r\n";

然后改成:

if (mail ($to, $subject, $body, $header))

这将显示来自姓名的邮件,同时仍然是 valid/properly 格式的电子邮件地址。


稍作编辑:

您在 $body 中还有一个未定义的变量 $name,根据 $from = $_POST['name'];,它应该是 $from,因为这是名称部分,但是在查看之后您的表单元素 <input name="from" placeholder="Ditt navn"> 在您的语言中看起来是 "name"。

需要改为 $from = $_POST['from'];

或更改<input name="from" placeholder="Ditt navn">

<input name="name" placeholder="Ditt navn">