Advertisement
Guest User

Untitled

a guest
May 12th, 2016
1,050
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AIMMS 5.32 KB | None | 0 0
  1. function send_mail($mail_to, $thema, $html2, $path, $logo_name='logo.png',$contacts=0,$em='')    
  2. {
  3.    
  4.     $val =  MAILGUN;
  5.     $val2 =  CONTACTFORMMAILGUN;
  6.    
  7.     if ($val=='true' or ($contacts==1 and $val2=='TRUE')) {
  8.     //$from='info@'.str_replace("www.","",$_SERVER['HTTP_HOST']);
  9.     $from="contacts@pharmacomstore.net";
  10.     $name = "Pharmacom Labs";
  11.     $from= $name.'<'.$from.'>';
  12.    
  13.     if ($contacts==1 and !filter_var($em, FILTER_VALIDATE_EMAIL) === false) {
  14.         $from= $em;
  15.     }
  16.    
  17.     $html =
  18.         '<html>'.
  19.             '<head>'.
  20.                 '<title>'.$thema.'</title>'.
  21.             '</head>'.
  22.             '<body>'.
  23.                 '<style>a { color:#777; } .list-sender p{margin:0px !important;}</style>'.
  24.                 '<div style="margin:0; padding:10px; background-color:#F2F2F2;">'.
  25.                     '<div style="width:650px; margin:0 auto; margin-top:10px; padding:15px; margin-bottom:10px; background-color:#fff; border-bottom:2px solid #D8D6D1;">'.
  26.                         '<p style="text-align:left; border-bottom: 1px solid #D8D6D1; padding-bottom: 25px;">'.
  27.                             '<a href="http://'.$_SERVER['HTTP_HOST'].'"><img src="cid:'.$logo_name.'" style="max-height: 65px;"></a>'.
  28.                         '</p>'.
  29.                         '<p style="height:10px;"></p>'.
  30.                         $html2.
  31.                         '<p style="min-height:10px"></p>'.
  32.                     '</div>'.
  33.                     '<p style="font-family:\'Helvetica\',\'Arial\',sans-serif;color:#9ca1ae;font-size:12px;font-weight:300;text-align:center;margin-bottom:10px;">© '.date("Y").' <a href="http://'.$_SERVER['HTTP_HOST'].'" style="color:#777" target="_blank">'.$_SERVER['HTTP_HOST'].'</a></p>'.
  34.                 '</div>'.
  35.             '</body>'.
  36.         '</html>';
  37.    
  38.  
  39.    
  40.     //$html = str_replace("cid:","",$html);
  41.    
  42.     $mailgunmes =
  43.     array(
  44.         'from' => $from,
  45.         'to' => $mail_to,
  46.         'subject' => $thema,
  47.         'html' => $html
  48.     );
  49.    
  50.     $i = 0;
  51.     foreach($path as $key=>$value) {
  52.         $mailgunmes['inline['.$i.']'] = "@".$value;
  53.         $i++;
  54.     }
  55.             $key='key-80158eb7ed7638cea435faa204bc660d';
  56.             $ch = curl_init();
  57.             curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  58.             curl_setopt($ch, CURLOPT_USERPWD, 'api:'.$key);
  59.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  60.  
  61.             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  62.             curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v3/pharmacomstore.net/messages');
  63.             curl_setopt($ch, CURLOPT_POSTFIELDS, $mailgunmes);
  64.             $result = curl_exec($ch);
  65.             curl_close($ch);
  66.    
  67.    
  68.     } else {
  69.                
  70.                 //$from='info@'.str_replace("www.","",$_SERVER['HTTP_HOST']);
  71.                 $from="contacts@pharmacomstore.net";
  72.                 $name = "Pharmacom Labs";
  73.                 $from= $name.'<'.$from.'>';
  74.                
  75.                 if ($contacts==1 and !filter_var($em, FILTER_VALIDATE_EMAIL) === false) {
  76.                     $from= $em;
  77.                 }  
  78.                 $html =
  79.                     '<html>'.
  80.                         '<head>'.
  81.                             '<title>'.$thema.'</title>'.
  82.                             '<style>a { color:#777;}  p{margin:0px !important;}</style>'.
  83.                         '</head>'.
  84.                         '<body>'.
  85.                             '<div style="margin:0; padding:10px; background-color:#F2F2F2;">'.
  86.                                 '<div style="width:650px; margin:0 auto; margin-top:10px; padding:15px; margin-bottom:10px; background-color:#fff; border-bottom:2px solid #D8D6D1;">'.
  87.                                     '<p style="text-align:left; border-bottom: 1px solid #D8D6D1; padding-bottom: 25px;">'.
  88.                                         '<a href="http://'.$_SERVER['HTTP_HOST'].'"><img src="cid:'.$logo_name.'" style="max-height: 65px;"></a>'.
  89.                                     '</p>'.
  90.                                     '<p style="height:10px;"></p>'.
  91.                                     $html2.
  92.                                     '<p style="min-height:10px"></p>'.
  93.                                 '</div>'.
  94.                                 '<p style="font-family:\'Helvetica\',\'Arial\',sans-serif;color:#9ca1ae;font-size:12px;font-weight:300;text-align:center;margin-bottom:10px;">© '.date("Y").' <a href="http://'.$_SERVER['HTTP_HOST'].'" style="color:#777" target="_blank">'.$_SERVER['HTTP_HOST'].'</a></p>'.
  95.                             '</div>'.
  96.                         '</body>'.
  97.                     '</html>';
  98.                
  99.                 $html=fix_newlines($html);
  100.                
  101.                 if (substr(strrchr($mail_to, "@"), 1)=='protonmail.ch' or substr(strrchr($mail_to, "@"), 1)=='protonmail.com') {
  102.                    
  103.                     $headers = "From: " . $from . "\r\n";
  104.                     $headers .= "Reply-To: ". $mail_to . "\r\n";
  105.                     //$headers .= "CC: ".$from."\r\n";
  106.                     $headers .= "MIME-Version: 1.0\r\n";
  107.                     $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  108.                    
  109.                     mail($mail_to, $thema, $html, $headers);
  110.                    
  111.                 } else {
  112.                
  113.                     $EOL = "\n";
  114.                     $boundary     = "--".(uniqid(time()));
  115.                     $headers    = "MIME-Version: 1.0;$EOL";    
  116.                     $headers   .= "From: ".$from."$EOL";  
  117.                     $headers   .= "Content-Type: multipart/related; boundary=\"$boundary\"$EOL";  
  118.                        
  119.                     $multipart  = "--{$boundary}$EOL";
  120.                     $multipart .= "Content-Type: text/html; charset=utf-8$EOL";    
  121.                     $multipart .= "Content-Transfer-Encoding: 8bit$EOL";
  122.                     $multipart .= $EOL;
  123.                     $multipart .= str_replace("\r\n", "\n", $html);
  124.                     $multipart .= $EOL;
  125.  
  126.                     if (!empty($path))
  127.                     {
  128.                       for($i = 0; $i < count($path); $i++)
  129.                       {
  130.                         $file = file_get_contents($path[$i]);
  131.                         $name = basename($path[$i]);
  132.                         $multipart .=  "$EOL--$boundary$EOL";    
  133.                         $multipart .= "Content-Type: image/jpeg; name=\"$name\"$EOL";
  134.                         $multipart .= "Content-Transfer-Encoding: base64$EOL";
  135.                         $multipart .= "Content-ID: <".$name.">$EOL";
  136.                         $multipart .= $EOL;
  137.                         $multipart .= chunk_split(base64_encode($file), 76, $EOL);
  138.                       }
  139.                     }
  140.  
  141.                     $multipart .= "$EOL--$boundary--$EOL";
  142.                    
  143.                     if(!mail($mail_to, $thema, $multipart, $headers)) { return false; } else { return true; }    
  144.                 }
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement