Send A Mailform To A Person From This List


You wish to be on the list?

By clicking on a person in the above list, a php-script will run on my server. This script recieves the pagename of the page where the username of this person is located. So you can only send a form to members of wikidot. This information is best kept in a private category. In this case the category is called "people".

So the php-script will access that page to get the username. The username will be used in a new page that will be created with the API. On that page there is a mailform and the person's username to whome it needs to be send will be rendered inside that mailform. In that way if the send button is pressed, this person will recieve the mail.

Things you need to have in order for this to work:

  • a form _template. This is a page that holds the template of the mailform people can send to specific users (in this case the peolpe in the list). In this mailform the "to"-attribute in the module is followed by "##USERNAME##". That is the string that will be replaced by the user's name. So leave it like that. You can adust the rest of the form. My form is loctated at
  • a page where visitors from your site can choose a name from a list. My list is located on this page and was generated with a listpages module, but you can as easely ust create a list by hand. The list should however have names that link to the php-script. In my case the link is constructed in the following manner:
  • Where
    • is my server
    • a-simple-plan is a directory on my server
    • send-form-to.php is the script
    • page=%%fullname%% is the name of the page that holds the user info in my case it wil be like "people:USERNUMBER" where USERNUMBER is replaced by the actual number.
    • %%form_data{title}%% What will be the visual link text. In my case the user-title
  • The php-script
// General settings
$page=$_GET['page']; //get pagenamefrom URL
$key="YOUR API KEY";
$username="YOUR USER NAME";
$ContentArray=getContentArray($site,$page,$username,$key); //get email
$title="Form will be send to ".$ContentArray["name"]; // build title
$mailFormContent=getPage($site,"mailform:_template","","","",$username,$key); //get mailform_template page info
$mailForm=$mailFormContent["content"]; // get mailform_template content
$mailForm=str_replace("##USERNAME##",$ContentArray["name"],$mailForm);// adjust mailform_template
createPage($site,"form".$page,$title,$mailForm,$username,$key);// create new mailpage
wait($site,"form".$page,10); // redirect after 10 miliseconds
If you wish to do some checking, un comment this blockand adjust waiting time
print ("<b>Pagename</b><br>http://$$page");
print ("<hr><b>Email</b><br>".$ContentArray["email"]);
print ("<hr><b>Title</b><br>".$title);
print ("<hr><b>MailForm _template</b><br>".$mailForm);
print ("<hr><b>Adjusted MailForm _template</b><br>".$mailForm);
print ("<hr><b>Mailform creation</b><br>OK");
    function getContentArray($site,$page,$username,$key)  // Gets form-page-content and converts to Array                      
    $content = $returnarray[content]; //copies string to a new string var
    $newarray = array();
    $newarray["parent_fullname"] = $returnarray[parent_fullname];
    $stringar = explode("\n",$content ); //split the content-string into an array of strings 
    foreach($stringar as $data)
        $data_ar = explode(":", $data, 2); //split the strings into form fields and form data
        $key = $data_ar[0];
        $cont = trim(trim($data_ar[1]),"'\""); //trimming off quotes and spaces
        if($key == '' && $$cont == '') ; //skip empty strings
        else $newarray[$key] = $cont;
    return $newarray;
    function getPage($site,$page,$username,$key)  // API methode pages.get_one                       
    $request = xmlrpc_encode_request("pages.get_one",$requestarray);          
    $context = stream_context_create(array('http' => array(                   
            'method' => "POST",                                               
            'header' => "Content-Type: text/xml",                             
            'content' => $request                                             
    $file = file_get_contents("https://".$username.":".$key.                  
    "", false, $context);                     
    $response = xmlrpc_decode($file);                                         
    if ($response && xmlrpc_is_fault($response))                              
        return ($response);
        return ($response);                                               
    function createPage($site,$page,$title,$content,$username,$key)                     //
               );                                                                       //
        $request = xmlrpc_encode_request("pages.save_one",$requestarray);               //
        $context = stream_context_create(array('http' => array(                         //
                'method' => "POST",                                                     //
                'header' => "Content-Type: text/xml",                                   //
                'content' => $request                                                   //
                )));                                                                    //
        $file = file_get_contents("https://".$username.":".$key.                        //
        "", false, $context);                           //                        
        $response = xmlrpc_decode($file);                                               //
        if ($response && xmlrpc_is_fault($response))                                    //
                {                                                                       //
                Print("Could not save page ".$page);                                    //
                trigger_error("Wikidot XML-RPC Error:                                   //
                $response[faultString] ($response[faultCode])");                        //
                }                                                                       //
    }                                                                                   //
    function wait($site,$page,$time)
function redirect()
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License