2014-12-23 00:58:00 +01:00
|
|
|
<?php
|
|
|
|
namespace Framadate\Services;
|
|
|
|
|
|
|
|
class MailService {
|
|
|
|
|
|
|
|
private $smtp_allowed;
|
|
|
|
|
|
|
|
function __construct($smtp_allowed) {
|
|
|
|
$this->smtp_allowed = $smtp_allowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isValidEmail($email) {
|
|
|
|
return filter_var($email, FILTER_VALIDATE_EMAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
function send($to, $subject, $body, $param = '') {
|
2015-04-14 22:32:41 +02:00
|
|
|
if ($this->smtp_allowed == true) {
|
2014-12-23 00:58:00 +01:00
|
|
|
mb_internal_encoding('UTF-8');
|
|
|
|
|
|
|
|
$subject = mb_encode_mimeheader(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'), 'UTF-8', 'B', "\n", 9);
|
|
|
|
|
|
|
|
$encoded_app = mb_encode_mimeheader(NOMAPPLICATION, 'UTF-8', 'B', "\n", 6);
|
|
|
|
$size_encoded_app = (6 + strlen($encoded_app)) % 75;
|
|
|
|
$size_admin_email = strlen(ADRESSEMAILADMIN);
|
|
|
|
|
|
|
|
if (($size_encoded_app + $size_admin_email + 9) > 74) {
|
|
|
|
$folding = "\n";
|
|
|
|
} else {
|
|
|
|
$folding = '';
|
|
|
|
};
|
|
|
|
|
|
|
|
$from = sprintf("From: %s%s <%s>\n", $encoded_app, $folding, ADRESSEMAILADMIN);
|
|
|
|
|
|
|
|
$headers = $from;
|
|
|
|
$headers .= 'Reply-To: ' . ADRESSEMAILREPONSEAUTO . "\n";
|
|
|
|
$headers .= "MIME-Version: 1.0\n";
|
2015-04-08 21:52:09 +02:00
|
|
|
$headers .= "Content-Type: text/html; charset=UTF-8\n";
|
2014-12-23 00:58:00 +01:00
|
|
|
$headers .= "Content-Transfer-Encoding: 8bit\n";
|
|
|
|
$headers .= "Auto-Submitted:auto-generated\n";
|
|
|
|
$headers .= 'Return-Path: <>';
|
|
|
|
|
2015-04-14 22:32:41 +02:00
|
|
|
$body = $body . '<br/><br/>' . __('Mail', 'Thanks for your trust.') . '<br/>' . NOMAPPLICATION . '<hr/>' . __('Mail', 'FOOTER');
|
2014-12-23 00:58:00 +01:00
|
|
|
|
|
|
|
mail($to, $subject, $body, $headers, $param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|