doushan7077 2015-08-06 13:13
浏览 53

使用form method = post with wordpress

I am trying to integrate a ‘subscribe to newsletter’ feature on my wordpress blog

Users just need to enter their name and email address, hit subscribe. This is then supposed to send me an email and I add them to the mailing list.

I activated the WP SMTP Mail plugin and entered in the relevant email server information to enable WordPress to send emails, asked WordPress to send me a test message and this worked.

Now I want to receive an email whenever someone fills in their name & email and hit subscribe.

If I do this at the moment it just takes me to newsletter_signup.php and I get at error message saying…

‘NOT FOUND Apologies, but no results were found for the requested post.’

Obviously this is not right and no email is being sent/received.

I have attached my code below, can anyone help me out here?

Thanks

Code for the signup form sidebar.php - This is not a plugin.

 <form action="newsletter_signup.php" method="post">
<p><input class="full" type="text" name="name" placeholder="Your name*"></p>
   <p><input class="full" type="email" name="Email" placeholder="Your email                                    address*"></p>
<p><input type="submit" class="sub-btn" value="Subscribe"></p>
                        </form>

newsletter_signup.php

<?php
$name = $_POST['name'];
$Email = $_POST['Email'];

$to = 'me@myself.com';      

wp_mail($to, $name, 'From: ' . $Email);
echo 'Your request Has Been Sent, Thank You. ';

?>
  • 写回答

1条回答 默认 最新

  • duanjia7607 2015-08-06 13:25
    关注

    You need to include wp-load.php to use wp functions like wp-mail.Here is the full code:

    <?php
    require_once('wp-load.php');
    $name = $_POST['name'];
    $Email = $_POST['Email'];
    $to = 'me@myself.com';      
    wp_mail($to, $name, 'From: ' . $Email);
    echo 'Your request Has Been Sent, Thank You. ';
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?