Skip to content

Instantly share code, notes, and snippets.

@pulketo
Created November 6, 2019 06:51
Show Gist options
  • Select an option

  • Save pulketo/7c6a4889d091a47f7314871ed9467273 to your computer and use it in GitHub Desktop.

Select an option

Save pulketo/7c6a4889d091a47f7314871ed9467273 to your computer and use it in GitHub Desktop.
sendmail wrapper for mailx
<?php
$fechora = date("YmdHis");$o="";
$stdin = "";
while (false !== ($line = fgets(STDIN))) {
$stdin.=$line;
}
list($H, $B) = explode(PHP_EOL.PHP_EOL, $stdin);
$header = explode(PHP_EOL, $H);
$body = explode(PHP_EOL, $B);
foreach($header as $eachHeader){
@list($k, $v) = explode(":", $eachHeader);
$k = strtolower(trim($k)); $v = trim($v);
switch($k){
case "from":
$from = $v;
break;
case "to":
$to = $v;
break;
case "subject":
$subject = $v;
break;
}
$B = trim($B);
}
// $o.=print_r($H,true);
// $o.=print_r($B,true);
$o.=print_r($header,true);
$o.=print_r($body,true);
$cmd = "echo '$B' | mailx -v -r '$from' -s '$subject' -S smtp='smtp.easyname.com:587' -S smtp-use-starttls -S smtp-auth=login -S smtp-auth-user='162997mail5' -S smtp-auth-password='XPVmweG8@#..' -S ssl-verify=ignore -S nss-config-dir='/etc/pki/nssdb/' $to";
$exe = trim(`$cmd`);
// $o.="cmd:$cmd";
file_put_contents("/tmp/sendmailpk.$fechora.log", $o);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment