Last active
November 15, 2016 09:32
-
-
Save h3nn3s/a3b3ae055a79b41cb72309bff1f2a1a5 to your computer and use it in GitHub Desktop.
Script to fetch post params from TYPO3s powermail Extension and send it to an email address (newsletter subscription for Supermailer). In order to use the BasicAuthProtection powermail needs this pull request to be merged: https://github.com/einpraegsam/powermail/pull/7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugin.tx_powermail.settings.setup { | |
marketing { | |
# Send Form values to CRM like salesforce or eloqua | |
sendPost { | |
# Activate sendPost (0/1) | |
_enable = TEXT | |
_enable.value = 1 | |
# Target URL for POST values (like http://www.target.com/target.php) | |
targetUrl = http://www.example.com/scripts/supermailer-powermail-crm.php?debug=1 | |
# build your post values like ¶m1=value1¶m2=value2 | |
values = COA | |
values { | |
5 = TEXT | |
5 { | |
# value from field {firstname} | |
field = anrede | |
wrap = &salutation=| | |
} | |
10 = TEXT | |
10 { | |
# value from field {firstname} | |
field = vorname | |
wrap = &first_name=| | |
} | |
15 = TEXT | |
15 { | |
# value from field {firstname} | |
field = nachname | |
wrap = &last_name=| | |
} | |
20 = TEXT | |
20 { | |
# value from field {e_mail} | |
field = e_mail | |
wrap = &to=| | |
} | |
30 = TEXT | |
30 { | |
wrap = &[email protected] | |
} | |
} | |
# Basic Auth Protection | |
username = username | |
password = password | |
# activate debug - log all configuration from curl settings to devlog (use extension devlog to view this values) | |
debug = 0 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mailer = new SupermailerPowermailCrm; | |
$mailer->sendMail(); | |
/** | |
* Fetch variables form powermail CRM service and send it to supermailer subscription | |
* This script only accepts POST variables | |
* supermailer-powermail-crm.php?debug=true&salutation=Herr&subject=subscribe&[email protected] | |
&first_name=max&last_name=muster&[email protected] | |
* | |
* @author Henrik Ziegenhain <[email protected]> | |
* @return void | |
*/ | |
class SupermailerPowermailCrm | |
{ | |
/** | |
* enable debug | |
* | |
* @var boolean | |
*/ | |
protected $debug = false; | |
/** | |
* mail subject | |
* | |
* @var string | |
*/ | |
protected $subject = 'SUBSCRIBE'; | |
/** | |
* mail to address | |
* | |
* @var string | |
*/ | |
protected $to = ''; | |
/** | |
* subscriber last name | |
* | |
* @var string | |
*/ | |
protected $lastName = ''; | |
/** | |
* subscriber first name | |
* | |
* @var string | |
*/ | |
protected $firstName = ''; | |
/** | |
* subscriber salutation | |
* | |
* @var string | |
*/ | |
protected $salutation = ''; | |
/** | |
* receiver name | |
* | |
* @var string | |
*/ | |
protected $recipient = ''; | |
/** | |
* Returns debug | |
* | |
* @return boolean $debig | |
*/ | |
public function getDebug() | |
{ | |
return $this->debug; | |
} | |
/** | |
* sets debug | |
* | |
* @param boolean $debug | |
* @return void | |
*/ | |
public function setDebug($debug) | |
{ | |
$this->debug = $debug; | |
} | |
/** | |
* Returns subject | |
* | |
* @return string $subject | |
*/ | |
public function getSubject() | |
{ | |
return $this->subject; | |
} | |
/** | |
* sets subject | |
* | |
* @param string $subject | |
* @return void | |
*/ | |
public function setSubject($subject) | |
{ | |
$this->subject = $subject; | |
} | |
/** | |
* Returns to address | |
* | |
* @return string $to | |
*/ | |
public function getTo() | |
{ | |
return $this->to; | |
} | |
/** | |
* sets to address | |
* | |
* @param string $to | |
* @return void | |
*/ | |
public function setTo($to) | |
{ | |
$this->to = $to; | |
} | |
/** | |
* Returns subscriber last name | |
* | |
* @return string $lastName | |
*/ | |
public function getLastName() | |
{ | |
return $this->lastName; | |
} | |
/** | |
* sets subscriber last name | |
* | |
* @param string $lastName | |
* @return void | |
*/ | |
public function setLastName($lastName) | |
{ | |
$this->lastName = $lastName; | |
} | |
/** | |
* Returns subscriber first name | |
* | |
* @return string $firstName | |
*/ | |
public function getFirstName() | |
{ | |
return $this->firstName; | |
} | |
/** | |
* sets subscriber first name | |
* | |
* @param string $firstName | |
* @return void | |
*/ | |
public function setFirstName($firstName) | |
{ | |
$this->firstName = $firstName; | |
} | |
/** | |
* Returns subscriber salutation | |
* | |
* @return string $salutation | |
*/ | |
public function getSalutation() | |
{ | |
return $this->salutation; | |
} | |
/** | |
* sets subscriber salutation | |
* | |
* @param string $salutation | |
* @return void | |
*/ | |
public function setSalutation($salutation) | |
{ | |
$this->salutation = $salutation; | |
} | |
/** | |
* Returns recipient address | |
* | |
* @return string $recipient | |
*/ | |
public function getRecipient() | |
{ | |
return $this->recipient; | |
} | |
/** | |
* sets recipient address | |
* | |
* @param string $recipient | |
* @return void | |
*/ | |
public function setRecipient($recipient) | |
{ | |
$this->recipient = $recipient; | |
} | |
public function __construct() { | |
if ((int)$_REQUEST['debug'] === 1 || $_REQUEST['debug'] === 'true') { | |
$this->setDebug(true); | |
} | |
if (!empty($_POST['subject'])) { | |
$this->setSubject(strtoupper($_POST['subject'])); | |
} | |
$email = $_POST['to']; | |
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
$this->setTo($email); | |
} | |
if (!empty($_POST['last_name'])) { | |
$this->setLastName(urldecode($_POST['last_name'])); | |
} | |
if (!empty($_POST['first_name'])) { | |
$this->setFirstName(urldecode($_POST['first_name'])); | |
} | |
if (!empty($_POST['salutation'])) { | |
$this->setSalutation($_POST['salutation']); | |
} | |
$recipient = $_POST['recipient']; | |
if (filter_var($recipient, FILTER_VALIDATE_EMAIL)) { | |
$this->setRecipient($recipient); | |
} | |
} | |
public function sendMail() { | |
$CRLF = "\r\n"; | |
/*if ($this->getDebug()) { | |
echo 'script entered<br>'; | |
echo 'Subject: ' . $this->getSubject() . '<br>'; | |
echo 'To: ' . $this->getTo() . '<br>'; | |
echo 'Name: ' . $this->getName() . '<br>'; | |
echo 'Recipient: ' . $this->getRecipient() . '<br>'; | |
}*/ | |
//$headers = 'From: ' . $this->getTo() .$CRLF; | |
//$headers .= 'Return-Path: <' . $this->getTo() . '>'.$CRLF; | |
$headers = 'From: ' . $this->getRecipient() .$CRLF; | |
$headers .= 'Return-Path: <' . $this->getRecipient() . '>'.$CRLF; | |
$headers .= "Content-type: text/plain; charset=utf-8".$CRLF; | |
# Alle uebergebenen Werte in die Nachricht uebernehmen | |
$message = ""; | |
$message .= 'Salutation: ' . $this->getSalutation() . "\n"; | |
$message .= 'EMail: ' . $this->getTo() . "\n"; | |
$message .= 'LastName: ' . $this->getLastName() . "\n"; | |
$message .= 'FirstName: ' . $this->getFirstName() . "\n"; | |
$message .= "IP: " . $_SERVER['REMOTE_ADDR'] . "\n"; | |
$message .= "DateTime: ".strftime("%x %X")."\n"; | |
if ($this->getDebug()) { | |
echo nl2br($message); | |
} | |
if(!mail($this->getRecipient(), $this->getSubject(), $message, $headers)) { | |
if ($this->getDebug()) { | |
echo "Can't send email {2}, PHP mail() must be configured properly."; | |
} | |
} else { | |
if ($this->getDebug()) { | |
echo 'send mail'; | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment