196 namespace Gino\Plugin;
198 require_once(LIB_DIR.OS.
'PHPMailer/class.phpmailer.php');
199 require_once(LIB_DIR.OS.
'PHPMailer/class.pop3.php');
200 require_once(LIB_DIR.OS.
'PHPMailer/class.smtp.php');
228 $this->_dft_view_folder = VIEWS_DIR;
243 $params[
'smtp_auth'] =
true;
244 $params[
'smtp_secure'] =
'tls';
245 $params[
'smtp_server'] =
"smtp.gmail.com";
246 $params[
'smtp_port'] = 587;
280 private function sendPhpMail($to, $subject, $message, $options=array()) {
282 $sender_email = array_key_exists(
'sender_email', $options) ? $options[
'sender_email'] : null;
283 $sender_name = array_key_exists(
'sender_name', $options) ? $options[
'sender_name'] : null;
284 $reply_email = array_key_exists(
'reply_email', $options) ? $options[
'reply_email'] : null;
285 $reply_name = array_key_exists(
'reply_name', $options) ? $options[
'reply_name'] : null;
286 $cc = array_key_exists(
'cc', $options) ? $options[
'cc'] : null;
287 $view_mailer = array_key_exists(
'view_mailer', $options) ? $options[
'view_mailer'] :
false;
288 $charset = array_key_exists(
'charset', $options) ? $options[
'charset'] :
'UTF-8';
289 $crlf = array_key_exists(
'crlf', $options) && $options[
'crlf'] ? $options[
'crlf'] :
"\r\n";
291 $additional_headers = null;
292 $additional_parameters = null;
294 if($sender_email || $reply_email || $view_mailer || $cc)
296 $additional_headers =
'';
300 $additional_headers .=
"From:";
301 if($sender_name) $additional_headers .= $sender_name.
" <";
302 $additional_headers .= $sender_email;
303 if($sender_name) $additional_headers .=
">";
305 if($reply_email || $view_mailer || $cc)
306 $additional_headers .= $crlf;
310 $additional_headers .=
"Reply-To:";
311 if($reply_name) $additional_headers .= $reply_name.
" <";
312 $additional_headers .= $reply_email;
313 if($reply_name) $additional_headers .=
">";
315 if($view_mailer || $cc)
316 $additional_headers .= $crlf;
320 $additional_headers .=
"X-Mailer: PHP/" . phpversion();
322 $additional_headers .= $crlf;
326 $additional_headers .=
"Cc:".$cc;
330 if($charset ==
'UTF-8')
332 $header_charset =
'MIME-Version: 1.0'.
"\r\n".
'Content-type: text/plain; charset=UTF-8'.$crlf;
333 $subject =
"=?UTF-8?B?".base64_encode($subject).
'?=';
334 $additional_headers = $header_charset.$additional_headers;
337 $send = \mail($to, $subject, $message, $additional_headers, $additional_parameters);
403 public function sendMail($recipient_email, $sender_email, $subject, $contents, $options=array()) {
405 $php_mail = array_key_exists(
'php_mail', $options) ? $options[
'php_mail'] :
true;
406 $mailer = array_key_exists(
'mailer', $options) ? $options[
'mailer'] :
'mail';
409 $sender_name = array_key_exists(
'sender_name', $options) ? $options[
'sender_name'] :
'';
410 $reply_email = array_key_exists(
'reply_email', $options) ? $options[
'reply_email'] :
'';
411 $reply_name = array_key_exists(
'reply_name', $options) ? $options[
'reply_name'] :
'';
412 $cc = array_key_exists(
'cc', $options) ? $options[
'cc'] :
'';
413 $ccn = array_key_exists(
'ccn', $options) ? $options[
'ccn'] :
'';
414 $notification = array_key_exists(
'notification', $options) ? $options[
'notification'] :
'';
417 $attachments = (array_key_exists(
'attachments', $options) && is_array($options[
'attachments'])) ? $options[
'attachments'] : array();
418 $embedded_images = (array_key_exists(
'embedded_images', $options) && is_array($options[
'embedded_images'])) ? $options[
'embedded_images'] : array();
421 $smtp_name = array_key_exists(
'smtp_name', $options) ? $options[
'smtp_name'] : null;
422 $smtp_secure = array_key_exists(
'smtp_secure', $options) ? $options[
'smtp_secure'] : null;
423 $smtp_server = array_key_exists(
'smtp_server', $options) ? $options[
'smtp_server'] :
'';
424 $smtp_port = array_key_exists(
'smtp_port', $options) ? $options[
'smtp_port'] : 25;
425 $smtp_auth = array_key_exists(
'smtp_auth', $options) ? $options[
'smtp_auth'] :
false;
426 $smtp_auth_type = array_key_exists(
'smtp_auth_type', $options) ? $options[
'smtp_auth_type'] : null;
427 $smtp_user = array_key_exists(
'smtp_user', $options) ? $options[
'smtp_user'] :
'';
428 $smtp_password = array_key_exists(
'smtp_password', $options) ? $options[
'smtp_password'] :
'';
431 $exception = array_key_exists(
'exception', $options) ? $options[
'exception'] :
false;
432 $debug = array_key_exists(
'debug', $options) ? $options[
'debug'] : 0;
433 $ishtml = array_key_exists(
'ishtml', $options) ? $options[
'ishtml'] :
true;
434 $charset = array_key_exists(
'charset', $options) ? $options[
'charset'] :
'UTF-8';
435 $priority = array_key_exists(
'priority', $options) ? $options[
'priority'] : 3;
436 $view_mailer = array_key_exists(
'view_mailer', $options) ? $options[
'view_mailer'] :
false;
439 $automatic_html = array_key_exists(
'automatic_html', $options) ? $options[
'automatic_html'] :
false;
440 $alternative_text = array_key_exists(
'alternative_text', $options) ? $options[
'alternative_text'] : null;
441 $crlf = array_key_exists(
'crlf', $options) && $options[
'crlf'] ? $options[
'crlf'] :
"\r\n";
442 $newline = array_key_exists(
'newline', $options) && $options[
'newline'] ? $options[
'newline'] :
"\r\n";
443 $word_wrap = array_key_exists(
'word_wrap', $options) && $options[
'word_wrap'] ? $options[
'word_wrap'] : 50;
447 return $this->
sendPhpMail($recipient_email, $subject, $contenuto,
449 'sender_email'=>$sender_email,
450 'sender_name'=>$sender_name,
451 'reply_email'=>$reply_email,
452 'reply_name'=>$reply_name,
455 'view_mailer'=>$view_mailer
460 $mail = new \PHPMailer($exception);
462 if($mailer ==
'mail') {
465 elseif($mailer ==
'sendmail') {
468 elseif($mailer ==
'qmail') {
471 elseif($mailer ==
'smtp') {
478 $mail->SMTPDebug = $debug;
479 $mail->Debugoutput =
'html';
480 $mail->Priority = $priority;
481 $mail->CharSet = $charset;
484 $mail->SetFrom($sender_email, $sender_name);
485 $mail->AddAddress($recipient_email);
486 if($reply_email) $mail->AddReplyTo($reply_email, $reply_name);
488 if($cc) $mail->AddCC($cc);
489 if($ccn) $mail->AddBCC($ccn);
490 if($notification) $mail->ConfirmReadingTo = $notification;
499 if(array_key_exists(
'smtp_auth', $params)) $smtp_auth = $params[
'smtp_auth'];
500 if(array_key_exists(
'smtp_secure', $params)) $smtp_secure = $params[
'smtp_secure'];
501 if(array_key_exists(
'smtp_server', $params)) $smtp_server = $params[
'smtp_server'];
502 if(array_key_exists(
'smtp_port', $params)) $smtp_port = $params[
'smtp_port'];
506 if($smtp_secure) $mail->SMTPSecure = $smtp_secure;
507 if($smtp_server) $mail->Host = $smtp_server;
508 if($smtp_port) $mail->Port = $smtp_port;
512 $mail->SMTPAuth = $smtp_auth;
513 $mail->Username = $smtp_user;
514 $mail->Password = $smtp_password;
516 if($smtp_auth_type) $mail->AuthType = $smtp_auth_type;
520 $mail->Subject = $subject;
522 $mail->IsHTML($ishtml);
523 $mail->Body = $contents;
524 $mail->WordWrap = $word_wrap;
528 if(!$alternative_text) {
529 $alternative_text =
'To view this email message, open it in a program that understands HTML!';
531 $mail->AltBody = $alternative_text;
535 if(count($embedded_images))
537 foreach($embedded_images AS $array) {
538 if(array_key_exists(
'path', $array) && array_key_exists(
'cid', $array))
540 $tmp_name = array_key_exists(
'name', $array) && $array[
'name'] ? $array[
'name'] :
'';
542 $mail->addEmbeddedImage($array[
'path'], $array[
'cid'], $tmp_name);
549 if(count($attachments))
551 foreach($attachments AS $array) {
553 if(array_key_exists(
'path', $array))
555 $tmp_name = array_key_exists(
'name', $array) && $array[
'name'] ? $array[
'name'] :
'';
557 $mail->AddAttachment($array[
'path'], $tmp_name);
562 if($automatic_html) {
563 $mail->msgHTML($contents);
572 echo
'Message was not sent.';
573 echo
'Mailer Error: '.$mail->ErrorInfo;