【问题标题】:Contact form on Yahoo Small Business Hosting雅虎小型企业托管联系表
【发布时间】:2013-08-20 00:08:00
【问题描述】:

我正在 Yahoo Small Business 托管上创建一个网站,但我在 Bluehost 上安装 WordPress 时使用的 PHP 联系表单存在问题。形式为:

    <?php
if(isset($_POST['submitted'])) {
if(trim($_POST['contactName']) === '') {
    $nameError = 'Please enter your name.';
    $hasError = true;
} else {
    $name = trim($_POST['contactName']);
}

if(trim($_POST['email']) === '')  {
    $emailError = 'Please enter your email address.';
    $hasError = true;
} else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
    $emailError = 'You entered an invalid email address.';
    $hasError = true;
} else {
    $email = trim($_POST['email']);
}

if(!isset($hasError)) {
    $emailTo = get_option('tz_email');
    if (!isset($emailTo) || ($emailTo == '') ){
        $emailTo = 'chris@bingetech.com';
    }
    $subject = '[PHP Snippets] From '.$name;
    $body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
    $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

    wp_mail($emailTo, $subject, $body, $headers);
    $emailSent = true;
}

} ?>
    <div id="contact-wrap">
        <?php if(isset($emailSent) && $emailSent == true)    
{ ?>
                            <div class="thanks">
                                    <p>Thanks, your email was sent successfully.</p>
                        </div>
                    <?php } else { ?>
                        <?php the_content(); ?>
                        <?php if(isset($hasError) || isset($captchaError)) { ?>
                            <p class="error">Sorry, an error occurred.<p>
                        <?php } } ?>

                    <form action="<?php the_permalink(); ?>" id="contactForm" method="post">
                        <ul class="formList">
                        <li>
                            <label class="contact_labels" for="contactName">Name:</label>
                            <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="required requiredField" />
                            <?php if($nameError != '') { ?>
                                <span class="error"><?=$nameError;?></span>
                            <?php } ?>
                        </li>

                        <li>
                            <label class="contact_labels" for="email">Email:&nbsp;</label>
                            <input type="email" name="email" id="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="required requiredField email" />
                            <?php if($emailError != '') { ?>
                                <span class="error"><?=$emailError;?></span>
                            <?php } ?>
                        </li>

                        </ul>
                            <div id="subContain">
                            <input type="submit" id="submit" value="Ask Away!"></input>
                            </div>


                    <input type="hidden" name="submitted" id="submitted" value="true" />
                </form>
    </div>

我有适当的标题调用,这在 Bluehost 上确实有效,根据我的研究,雅虎小型企业托管似乎在联系表格/电子邮件方面可能很棘手。我怎样才能解决这个问题?

【问题讨论】:

  • 错误/问题是什么?
  • @Scott Helme 尽管有“成功”消息,但从未发送任何电子邮件。
  • 试着把它归结为基础,注释掉所有内容,看看你是否可以调用 mail() 并且它会发送。如果这不起作用,除了您的代码之外,还有其他需要查看的内容。
  • 有什么特别的原因要使用wp_mail吗?我有各种由 Yahoo 托管的网站,标准的 PHP“邮件”工作正常。

标签: php html wordpress hosting yahoo


【解决方案1】:

您应该使用一些插件而不是您自己的 PHP 代码。试试 Contact form 7,它完全可以自定义

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-08
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 2020-10-08
    相关资源
    最近更新 更多