2

I have a newsletter form in my wordpress site which supposed to be used through the shortcode :

<form action="newsletter.php" method="post">
... 
</form>

And the shortcode should look :

[newsletter]

In my theme option i have an input field to enter the email address. That value needs to be stored in newsletter.php in the variable $to

How can i 'connect' the newsletter.php with the wordpress get_option for that input i have?

newsletter.php :

<?php
$email = $_POST['news'];

// --- this should be the option from the wordpress panel -------
$to = "[email protected]";
// ---------------------------------


$subject = "newsletter request";


$date = date("d-m-Y");


$email_message = " Newsletter request : \r\n";
$email_message .= " ================================================== \r\n ";
$email_message .= "This user wants to be notified about your website launch : ".$email."\r\n";
$email_message .= " ================================================== \r\n";
$email_message .= " Request was sent " .$date. " \r\n";

$headers = 'From: '.$email."\r\n";


if($email != null && $email != ""){

mail($to,$subject,$email_message,$headers);
}

header("location:../index.php");

?>

I tried with REQUIRE_ONCE but, that isn't working...

2
  • maybe I don't understand but for why you need require - request got to newsletter.php automaticly. If I miss please more explaine whta really you want . I mean which file you need to require to in which. Thanks nas sorry if I miss Commented Sep 3, 2011 at 17:53
  • $to doesn't change when I change it in my admin panel... Have any idea how can i do that? Commented Sep 3, 2011 at 18:07

1 Answer 1

1

Well you have to create a plugin, I am giving instruction to create a simple plugin. I say again SIMPLE. And its not the only way to create a plugin, but it will be easy one for you.

Create a file in plugins folder and do code like this

/**
 * @package Simple Plugin
 * @version 0.0.1
 */
/*
Plugin Name: Usman
Author: Muhammad Usman
Version: 0.0.1
*/

function showpage($content)
{
    if(stristr($content,'[myplugin]'))
        {
         if(isset($_POST['your-field']))
         {
          //Write your code
          //Save fields or so

          $content="Form submitted";
         }


    }

    return $content;
}

add_filter("the_content","showpage");

Activate this plugin from admin panel and create a page, write [myplugin] in content. And give your form action to this page's permalink.

More details can be found at http://codex.wordpress.org/Writing_a_Plugin

Sign up to request clarification or add additional context in comments.

2 Comments

Does it have to be plugin, can i for example insert in my header.php something like if(isset($_POST['your-field'])) { //Write your code } ... ?
Its not a proper way. You won't be able handle messages to be given properly when you accept all fields or if you deny etc. There are also other problems, after all this is not an efficient way and creating a plugin will be easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.