douqiao3930 2016-06-23 15:29
浏览 67

测试联系电子邮件Wordpress模板不发送

I've been trying to figure this out for hours, but can't figure out what I'm doing wrong.

I've created a Wordpress contact page, but when I try to send the test email to myself, nothing ever comes through. I'm not getting any errors or anything-- what am I missing here? Thanks for looking, and let me know if you need any extra information.

HTML/PHP:

<!--------------- YOUR INFO -------------------->
<div class="col-xs-10 col-xs-offset-1 col-lg-6 col-lg-offset-3" id="contactWrapper">
    <h3 id="contactSectionHeader" class="p-t-2"><i class="fa fa-plus-square-o"></i> YOUR INFORMATION</h3>

    <form class="form-horizontal" role="form" method="post" action="contactform.php">
    <div class="form-group">
        <label for="name" class="col-sm-2 control-label">Name</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="">
            <?php echo "<p class='text-danger'>$errName</p>";?>
        </div>
    </div>
    <div class="form-group">
        <label for="email" class="col-sm-2 control-label">Email</label>
        <div class="col-sm-10">
            <input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" value="">
            <?php echo "<p class='text-danger'>$errEmail</p>";?>
        </div>
    </div>
    <div class="form-group">
        <label for="message" class="col-sm-2 control-label">Message</label>
        <div class="col-sm-10">
            <textarea class="form-control" rows="4" name="message"></textarea>
            <?php echo "<p class='text-danger'>$errMessage</p>";?>
        </div>
    </div>
    <div class="form-group">
        <label for="human" class="col-sm-2 control-label">2 + 3 = ?</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="human" name="human" placeholder="Your Answer">
                        <?php echo "<p class='text-danger'>$errHuman</p>";?>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-10 col-sm-offset-2">
            <input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-10 col-sm-offset-2">
            <?php echo $result; ?>  
        </div>
    </div>
</form>

</div>

PHP/SEND PAGE:

<?php
    if (isset($_POST["submit"])) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $human = intval($_POST['human']);
        $from = 'Demo Contact Form'; 
        $to = 'brandon@brandonstiles.com';
        $subject = 'Message from Contact Demo ';

        $body = "From: $name
 E-Mail: $email
 Message:
 $message";

        // Check if name has been entered
        if (!$_POST['name']) {
            $errName = 'Please enter your name';
        }

        // Check if email has been entered and is valid
        if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
            $errEmail = 'Please enter a valid email address';
        }

        //Check if message has been entered
        if (!$_POST['message']) {
            $errMessage = 'Please enter your message';
        }
        //Check if simple anti-bot test is correct
        if ($human !== 5) {
            $errHuman = 'Your anti-spam is incorrect';
        }

// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
    if (wp_mail ($to, $subject, $body, $from)) {
        $result='<div class="alert alert-success">Thank You! I will be in touch</div>';
    } else {
        $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
    }
}
    }
?>
  • 写回答

1条回答 默认 最新

  • doucheng7534 2016-06-23 17:03
    关注

    First you should allow errors in php:

    error_reporting(E_ALL);
    

    on the top of the page.

    And put the following into your wp-config.php:

    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true);
    define('WP_DEBUG_DISPLAY', false);
    @ini_set('display_errors', 0);
    

    Second you should check if your server has sendmail enabled.

    You can make this with a short search in the php information.

    Make a new .php file with the following content:

    <?php
    phpinfo();
    

    then search after "sendmail".

    Third you should check if your webhoster has special requirements for sending mails with php. For example, a big german webhoster does only allow php mails with additional_parameters.

    And last you should check if your code has all requirements from wordpress and check each line of the code with a debugger. Or make a new .php file with a working mail function on your server to test if the problem is your server or your script.

    If you have access to the server logs, you should check them too.

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行