Difference between revisions of "Extension:FormMailer"

From Organic Design wiki
m
Line 37: Line 37:
 
'url'        => 'http://www.mediawiki.org/wiki/Extension:FormMailer',
 
'url'        => 'http://www.mediawiki.org/wiki/Extension:FormMailer',
 
'version'    => FORMMAILER_VERSION
 
'version'    => FORMMAILER_VERSION
);
+
);
  
 
function wfSetupFormMailer() {
 
function wfSetupFormMailer() {
Line 55: Line 55:
 
elseif ($k == 'formmailer_subject') $subject = $v;
 
elseif ($k == 'formmailer_subject') $subject = $v;
 
elseif ($k != $wgFormMailerVarName) $body .= "$k: $v\n\n";
 
elseif ($k != $wgFormMailerVarName) $body .= "$k: $v\n\n";
}
+
}
  
 
# Send to recipients using the MediaWiki mailer
 
# Send to recipients using the MediaWiki mailer
Line 65: Line 65:
 
$user->setEmail($recipient);
 
$user->setEmail($recipient);
 
if ($user->sendMail($subject,$body,$from) !== true) $err = 'Failed to send!';
 
if ($user->sendMail($subject,$body,$from) !== true) $err = 'Failed to send!';
}
+
}
 
$wgSiteNotice .= "<div class='usermessage'>".($err ? $err : $message)."</div>";
 
$wgSiteNotice .= "<div class='usermessage'>".($err ? $err : $message)."</div>";
}
 
 
}
 
}
 +
}

Revision as of 01:46, 18 August 2008

<?php

  1. Extension:FORMMAILERTemplate:Php
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.
  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:Nad
  3. - Started: 2007-06-17
  4. - See http://www.mediawiki.org/wiki/Extension:FormMailerfor installation and usage details

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('FORMMAILER_VERSION','1.0.1, 2007-08-08');

  1. A list of email addresses which should recieve posted forms

$wgFormMailerRecipients = array();

  1. If a variable of this name is posted, the data is assumed to be for mailing

$wgFormMailerVarName = "formmailer";

  1. Name of sender of forms

$wgFormMailerFrom = 'wiki@'.ereg_replace('^.+www.',,$wgServer);

  1. Don't post the following posted items

$wgFormMailerDontSend = array('title','action');

  1. Message to display after sending the form (can also be set in the form by posting formmailer_message

$wgFormMailerMessage = "Thanks, your enquiry has been submitted!";

  1. Message to display after sending the form (can also be set in the form by posting formmailer_subject

$wgFormMailerSubject = "Form submitted from $wgSitename";


$wgExtensionFunctions[] = 'wfSetupFormMailer';

$wgExtensionCredits['other'][] = array( 'name' => 'FormMailer', 'author' => 'User:Nad', 'description' => 'Formats and sends posted form fields to email recipients', 'url' => 'http://www.mediawiki.org/wiki/Extension:FormMailer', 'version' => FORMMAILER_VERSION );

function wfSetupFormMailer() { global $wgFormMailerVarName,$wgFormMailerRecipients,$wgFormMailerMessage,$wgFormMailerSubject, $wgFormMailerFrom,$wgFormMailerDontSend,$wgSimpleFormsRequestPrefix,$wgSiteNotice,$wgSitename;

if (isset($_REQUEST[$wgSimpleFormsRequestPrefix.$wgFormMailerVarName])) {

# Construct the message $body = "Form posted from ".$_SERVER['REMOTE_ADDR']."\n\n"; $message = $wgFormMailerMessage; $subject = $wgFormMailerSubject; foreach (array_merge($_GET,$_POST) as $k => $v) if (!in_array($k,$wgFormMailerDontSend)) { if ($wgSimpleFormsRequestPrefix) $k = ereg_replace("^$wgSimpleFormsRequestPrefix",,$k); $k = str_replace('_',' ',$k); if ($k == 'formmailer_message') $message = $v; elseif ($k == 'formmailer_subject') $subject = $v; elseif ($k != $wgFormMailerVarName) $body .= "$k: $v\n\n"; }

# Send to recipients using the MediaWiki mailer $err = ; $user = new User(); $from = "\"$wgSitename\"<$wgFormMailerFrom>"; foreach ($wgFormMailerRecipients as $recipient) if (User::isValidEmailAddr($recipient)) { $user->setName($recipient); $user->setEmail($recipient); if ($user->sendMail($subject,$body,$from) !== true) $err = 'Failed to send!'; }

$wgSiteNotice .= "

".($err ? $err : $message)."

";

} }