init
This commit is contained in:
110
standalone/send_mail.php
Executable file
110
standalone/send_mail.php
Executable file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
ini_set('default_charset', 'UTF-8');
|
||||
header('Content-Type: text/html; charset='.'UTF-8');
|
||||
mb_internal_encoding('UTF-8');
|
||||
mb_http_output('UTF-8');
|
||||
mb_http_input('UTF-8');
|
||||
mb_language('uni');
|
||||
mb_regex_encoding('UTF-8');
|
||||
|
||||
//Main
|
||||
$sApiKey = isset($_POST['api_key'])?$_POST['api_key']:'';
|
||||
$sApp = isset($_POST['app'])?$_POST['app']:'lutran.fr';
|
||||
$sFromName = isset($_POST['from_name'])?$_POST['from_name']:'';
|
||||
$sFromEmail = isset($_POST['from_email'])?$_POST['from_email']:'www-data@lutran.fr';
|
||||
$sSubject = isset($_POST['subject'])?$_POST['subject']:'';
|
||||
$sMsg = isset($_POST['msg'])?$_POST['msg']:'';
|
||||
$sToEmail = isset($_POST['to_email'])?$_POST['to_email']:'';
|
||||
$asCc = isset($_POST['cc_email'])?json_decode($_POST['cc_email'], true):'';
|
||||
$bSelfMail = isset($_POST['self'])?$_POST['self']:true;
|
||||
|
||||
$asAuthorizedApi = array('Wedding'=>'8D98B36BB558BC6771324AEFB9E37');
|
||||
if(array_key_exists($sApp, $asAuthorizedApi) && $sApiKey = $asAuthorizedApi[$sApp])
|
||||
{
|
||||
$sResult = sendEmail($sApp, $sFromName, $sFromEmail, $sSubject, $sMsg, $sToEmail, $asCc, $bSelfMail);
|
||||
}
|
||||
else $sResult = 1;
|
||||
|
||||
echo $sResult;
|
||||
|
||||
//Functions
|
||||
function sendEmail($sApp, $sFromName, $sFromEmail, $sSubject, $sMsg, $sToEmail, $asCc, $bSelfMail)
|
||||
{
|
||||
$sResult = 0;
|
||||
if($sFromName!='' && $sFromEmail!='' && $sSubject!='' && $sMsg!='' && $sToEmail!='')
|
||||
{
|
||||
//Message
|
||||
$sHtmlMessage = '';
|
||||
if($bSelfMail)
|
||||
{
|
||||
$sHtmlMessage = 'From: '.$sFromName."<br />".
|
||||
'Email: '.$sFromEmail."<br /><br />".
|
||||
'Subject: '.$sSubject."<br />".
|
||||
'Message: <br /><br />';
|
||||
$sFromName = $sApp;
|
||||
$sSubject = $sApp.' - Contact';
|
||||
}
|
||||
$sHtmlMessage .= str_replace("\n", '<br />', $sMsg);
|
||||
$sPlainMessage = strip_tags(str_replace('<br />', "\n", $sHtmlMessage));
|
||||
|
||||
//Email
|
||||
$iBoundary = uniqid("HTMLEMAIL");
|
||||
$sCc = empty($asCc)?'':('Cc: '.implodeAll($asCc, ' <', "\r\n, ", '', '>')."\r\n");
|
||||
$sHeaders = 'From: '.$sFromName.' <www-data@lutran.fr>'."\r\n".
|
||||
'Reply-To: '.$sFromName.' <www-data@lutran.fr>'."\r\n".
|
||||
$sCc.
|
||||
'MIME-Version: 1.0'."\r\n".
|
||||
'Content-Type: multipart/alternative;'.
|
||||
'boundary = '.$iBoundary."\r\n\r\n".
|
||||
'MIME encoded Message'.
|
||||
'--'.$iBoundary."\r\n".
|
||||
'Content-Type: text/plain; charset=UTF-8'."\r\n".
|
||||
'Content-Transfer-Encoding: base64'."\r\n\r\n".
|
||||
chunk_split(base64_encode($sPlainMessage)).
|
||||
'--'.$iBoundary."\r\n".
|
||||
'Content-Type: text/html; charset=UTF-8'."\r\n".
|
||||
'Content-Transfer-Encoding: base64'."\r\n\r\n".
|
||||
chunk_split(base64_encode($sHtmlMessage));
|
||||
|
||||
//Store in case email fails
|
||||
//@file_put_contents('log.html', '<br />----<br /><br />'.$sHtmlMessage, FILE_APPEND);
|
||||
|
||||
//Send
|
||||
if(mail($sToEmail, $sSubject, '', $sHeaders))
|
||||
{
|
||||
$sResult = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sResult = 3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sResult = 4;
|
||||
}
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
function implodeAll($asText, $asKeyValueSeparator='', $sRowSeparator='', $sKeyPre='', $sValuePost=false)
|
||||
{
|
||||
if($sValuePost===false)
|
||||
{
|
||||
$sValuePost = $sKeyPre;
|
||||
}
|
||||
$asCombinedText = array();
|
||||
|
||||
//if unique value for key value separator
|
||||
if(!is_array($asKeyValueSeparator) && !empty($asText))
|
||||
{
|
||||
$asKeyValueSeparator = array_combine(array_keys($asText), array_fill(0, count($asText), $asKeyValueSeparator));
|
||||
}
|
||||
|
||||
foreach($asText as $sKey=>$sValue)
|
||||
{
|
||||
$asCombinedText[] = $sKeyPre.$sKey.$asKeyValueSeparator[$sKey].(is_array($sValue)?implode($sValue):$sValue).$sValuePost;
|
||||
}
|
||||
return implode($sRowSeparator, $asCombinedText);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user