联系字段不起作用

时间:2015-01-09 11:16:49

标签: php html wordpress

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

你可以帮我看看有什么不对吗?

一年前我测试它时,我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>');
}
?>

1 个答案:

答案 0 :(得分:2)

$from中的if (mail ($to, $subject, $body, $from))变量是邮件将其用作默认From:的标题部分,而$from = $_POST['name'];则取自John@inexistant_user_on_yourserver.xxx作为&#34 ;名称&#34 ;.邮件正在阅读&#34;来自:&#34;作为一个名字。它必须是电子邮件地址。

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

邮件正在以xxx@your_hosting_provider_mail.xxx的形式阅读/解读,因此会回到john@his_email_service.xxx作为&#34;来自:&#34;而不是$email

您需要将该变量更改为if (mail ($to, $subject, $body, $email)) ,以便您的代码现在显示为

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

有关此内容的更多信息,请阅读手册:

因此,您可以添加:

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

然后将其更改为:

$name

将显示来自名称的邮件,同时仍然是有效/格式正确的电子邮件地址。


轻微编辑:

$body中还有一个未定义的变量$from应该是$from = $_POST['name'];,因为这是<input name="from" placeholder="Ditt navn">的名称部分,但在查看表单后#39; s元素$from = $_POST['from'];,它的意思是&#34; name&#34;用你的语言。

需要将其更改为<input name="from" placeholder="Ditt navn">

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

到{{1}}