Skip to content

Commit

Permalink
Rewrite for .24
Browse files Browse the repository at this point in the history
  • Loading branch information
Lewis Goddard committed Dec 3, 2014
1 parent dba39b5 commit b125447
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 169 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Browning_Config.php
Recaptcha_Config.php
config.browning.php
30 changes: 0 additions & 30 deletions Browning_Config_Example.php

This file was deleted.

103 changes: 0 additions & 103 deletions Browning_Send.php

This file was deleted.

10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ To use, do somethings like this.
// If you're ready to fire
if ( isset($_POST['dear']) && isset($_POST['subject']) && isset($_POST['message']) ) {
require 'Browning_Send.php';
require 'config.browning.php';
require 'function.browning.php';
$Mail = Browning_Send($_POST['dear'], $_POST['subject'], $_POST['message'], $_POST['regards'], '');
$Mail = Browning($_POST['dear'], $_POST['subject'], $_POST['message'], $_POST['regards'], '');
/* Browning_Send(
'to email',
Expand All @@ -26,10 +27,11 @@ if ( isset($_POST['dear']) && isset($_POST['subject']) && isset($_POST['message'
debug [boolean: true, false; default: false;]
); */
if ( $Mail === true ) {
if ( $Mail['Success'] ) {
echo '<h2>Success!</h2>';
} else {
echo '<h2>Error: '.$Mail.'</h2>';
echo '<h2>Failure!</h2>';
var_dump($Mail);
}
} else {
Expand Down
4 changes: 0 additions & 4 deletions Recaptcha_Config_Example.php

This file was deleted.

File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions form.php → assets/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@
<div class="col span_3_of_12"><br></div>
<div class="col span_6_of_12">
<?php
// TODO Check exists / is readable.
require 'Recaptcha_Config.php';
if ( $Recaptcha ) {
require 'recaptchalib.php' ;
echo recaptcha_get_html($Recaptcha_Public);
// TODO Check exists / is readable.
require_once $Recaptcha['Location'];
echo recaptcha_get_html($Recaptcha['Public']);
}
?>
</div>
Expand Down
2 changes: 1 addition & 1 deletion header.php → assets/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<link rel="shortcut icon" href="//eustasy.org/favicon.ico">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic">
<link rel="stylesheet" href="//labs.eustasy.org/style.css">
<link rel="stylesheet" href="browning.css">
<link rel="stylesheet" href="assets/browning.css">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand Down
48 changes: 48 additions & 0 deletions config.browning.example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

//// Browning: A Mailgun Script (v0.24)
// https://github.com/eustasy/browning-a-mailgun-script

//// Mailgun
// Sign up at https://mailgun.com/signup
// First 10,00 mails a month free.

// Mailgun API URL
// Replace example.com with your domain after signing up at
// $Browning['URL'] = 'https://api.mailgun.net/v2/example.com';
$Browning['URL'] = 'https://api.mailgun.net/v2/example.com';

// Mailgun API Key
// Use API Key found at https://mailgun.com/cp
// $Browning['Key'] = 'key-123456-abcdefg-789012-abc-34567';
$Browning['Key'] = 'key-123456-abcdefg-789012-abc-34567';
// Not the Public Key. We don't need that.

// From for Mail
// $Browning['Default']['Regards'] = 'Example Support';
$Browning['Default']['Regards'] = 'Example Support';

// Reply-to address
// Please don't use noreply.
// Should match the domain in your API URL.
// $Browning['Default']['ReplyTo'] = '[email protected]';
$Browning['Default']['ReplyTo'] = '[email protected]';

//// Recaptcha
// Sign up at https://www.google.com/recaptcha/admin

// Enable

// You shouldn't need to change this unless you move the file.
$Recaptcha['Location'] = __DIR__.'/libs/recaptchalib.php';

// This is the public key you got from Google.
// They call this a "Site key".
$Recaptcha['Public'] = '0123456789abcdefghijklmnopqrstvwxyzABCDE';

// This is the secret one. Don't get them mixed up!
$Recaptcha['Secret'] = 'FGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghi';

// Disable

// $Recaptcha = false;
102 changes: 102 additions & 0 deletions function.browning.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

/*
Browning: A Mailgun Script (v0.24)
https://github.com/eustasy/browning-a-mailgun-script
====================================================
Browning is a tiny PHP function to send emails with Mailgun,
that uses CURL instead of Mailgun's (slightly porky) library.
Copyright (c) 2014 eustasy under the MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

function Browning($Dear, $Subject, $Message, $Regards = false, $ReplyTo = false, $Debug = false) {

global $Browning, $Recaptcha;

if ( empty($Dear) ) {
return array('Error' => 'No email address defined for recipient.', 'Success' => false);

} else if ( empty($Subject) ) {
return array('Error' => 'No subject for message.', 'Success' => false);

} else if ( empty($Message) ) {
return array('Error' => 'You must enter a message, to send a message.', 'Success' => false);

} else {

$Browning['Dear'] = $Dear;
$Browning['Subject'] = $Subject;
$Browning['Message'] = $Message;

if ( $Regards ) {
$Browning['Regards'] = $Regards;
} else {
$Browning['Regards'] = $Browning['Default']['Regards'];
}

if ( $ReplyTo ) {
$Browning['ReplyTo'] = $ReplyTo;
} else {
$Browning['ReplyTo'] = $Browning['Default']['ReplyTo'];
}

$Browning['Curl'] = curl_init();

curl_setopt($Browning['Curl'], CURLOPT_URL, $Browning['URL'].'/messages');
curl_setopt($Browning['Curl'], CURLOPT_RETURNTRANSFER, true);
curl_setopt($Browning['Curl'], CURLOPT_USERPWD, 'api:'.$Browning['Key']);
curl_setopt($Browning['Curl'], CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt_array($Browning['Curl'], array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'from' => $Browning['Regards'].' <'.$Browning['ReplyTo'].'>',
'to' => $Browning['Dear'],
'subject' => $Browning['Subject'],
'text' => $Browning['Message']
)
));

$Browning['Response'] = curl_exec($Browning['Curl']);
$Browning['Info'] = curl_getinfo($Browning['Curl']);

if ( $Debug ) {
var_dump($Browning['Response']);
var_dump($Browning['Info']);
}

if ( curl_errno($Browning['Curl']) ) {
return curl_errno($Browning['Curl']).' Error: '.curl_error($Browning['Curl']);

} else if ( !$Browning['Response'] ) {
return array('Error' => 'Unable to send email. Check your configuration and keys.', 'Success' => false);

} else {
curl_close($Browning['Curl']);
return array('Error' => false, 'Success' => true);
}

}

}
Loading

0 comments on commit b125447

Please sign in to comment.