Changeset 24951
- Timestamp:
- Oct 17, 2013, 3:05:30 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/config_default.inc.php
r23499 r24951 263 263 $conf['smtp_password'] = ''; 264 264 265 // 'ssl' or 'tls' 266 $conf['smtp_secure'] = null; 265 267 266 268 // check_upgrade_feed: check if there are database upgrade required. Set to -
trunk/include/functions_mail.inc.php
r23823 r24951 26 26 // +-----------------------------------------------------------------------+ 27 27 28 29 /**30 * Encodes a string using Q form if required (RFC2045)31 * mail headers MUST contain only US-ASCII characters32 */33 function encode_mime_header($str)34 {35 $x = preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);36 if ($x==0)37 {38 return $str;39 }40 // Replace every high ascii, control =, ? and _ characters41 $str = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',42 "'='.sprintf('%02X', ord('\\1'))", $str);43 44 // Replace every spaces to _ (more readable than =20)45 $str = str_replace(" ", "_", $str);46 47 global $lang_info;48 return '=?'.get_pwg_charset().'?Q?'.$str.'?=';49 }50 51 28 /* 52 29 * Returns the name of the mail sender : … … 91 68 'smtp_user' => $conf['smtp_user'], 92 69 'smtp_password' => $conf['smtp_password'], 93 ' boundary_key' => generate_key(32),70 'smtp_secure' => $conf['smtp_secure'], 94 71 ); 95 72 … … 98 75 99 76 // name of the webmaster is the title of the gallery 100 $conf_mail['formated_email_webmaster'] = 101 format_email(get_mail_sender_name(), $conf_mail['email_webmaster']); 77 $conf_mail['formated_email_webmaster'] = format_email(get_mail_sender_name(), $conf_mail['email_webmaster']); 102 78 103 79 return $conf_mail; … … 118 94 if ($cvt_name!="") 119 95 { 120 $cvt_name = encode_mime_header( 121 '"' 122 .addcslashes($cvt_name,'"') 123 .'"'); 124 $cvt_name .= ' '; 96 $cvt_name = '"'.addcslashes($cvt_name,'"').'"'.' '; 125 97 } 126 98 … … 349 321 'content' => $content, 350 322 'content_format' => 'text/plain', 351 'email_format' => 'text/ plain',323 'email_format' => 'text/html', 352 324 ) 353 325 ); … … 516 488 } 517 489 518 if (empty($args['email_format'])) 519 { 520 $args['email_format'] = $conf_mail['default_email_format']; 521 } 522 490 include_once(PHPWG_ROOT_PATH.'include/class.phpmailer.php'); 491 492 $mail = new PHPMailer; 493 494 foreach (explode(',', get_strict_email_list($to)) as $recipient) 495 { 496 $mail->addAddress($recipient); 497 } 498 499 $mail->WordWrap = 76; 500 $mail->CharSet = 'UTF-8'; 501 523 502 // Compute root_path in order have complete path 524 503 set_make_full_url(); … … 526 505 if (empty($args['from'])) 527 506 { 528 $args['from'] = $conf_mail['formated_email_webmaster']; 507 $mail->From = get_webmaster_mail_address(); 508 $mail->FromName = get_mail_sender_name(); 509 510 $mail->addReplyTo(get_webmaster_mail_address(), get_mail_sender_name()); 529 511 } 530 512 else 531 513 { 532 $args['from'] = format_email('', $args['from']); 533 } 534 514 $mail->From = $args['from']; 515 $mail->addReplyTo($args['from']); 516 } 517 518 // Subject 535 519 if (empty($args['subject'])) 536 520 { 537 521 $args['subject'] = 'Piwigo'; 538 522 } 539 // Spring cleaning 540 $cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject'])); 541 // Ascii convertion 542 $cvt_subject = encode_mime_header($cvt_subject); 523 524 $args['subject'] = trim(preg_replace('#[\n\r]+#s', '', $args['subject'])); 525 526 $mail->Subject = $args['subject']; 527 528 // Cc 529 if (!empty($args['Cc'])) 530 { 531 $mail->addCC($args['Cc']); 532 } 533 534 // Bcc 535 if ($conf_mail['send_bcc_mail_webmaster']) 536 { 537 $args['Bcc'][] = get_webmaster_mail_address();; 538 } 539 540 if (!empty($args['Bcc'])) 541 { 542 $headers.= 'Bcc: '.implode(',', $args['Bcc'])."\n"; 543 544 foreach ($args['Bcc'] as $bcc) 545 { 546 $mail->addBCC($bcc); 547 } 548 } 549 550 // content 551 if (empty($args['email_format'])) 552 { 553 $args['email_format'] = $conf_mail['default_email_format']; 554 } 543 555 544 556 if (!isset($args['content'])) … … 552 564 } 553 565 554 if ($conf_mail['send_bcc_mail_webmaster'])555 {556 $args['Bcc'][] = $conf_mail['formated_email_webmaster'];557 }558 559 566 if (empty($args['theme'])) 560 567 { … … 562 569 } 563 570 564 $headers = 'From: '.$args['from']."\n";565 $headers.= 'Reply-To: '.$args['from']."\n";566 567 if (!empty($args['Cc']))568 {569 $headers.= 'Cc: '.implode(',', $args['Cc'])."\n";570 }571 572 if (!empty($args['Bcc']))573 {574 $headers.= 'Bcc: '.implode(',', $args['Bcc'])."\n";575 }576 577 $headers.= 'Content-Type: multipart/alternative;'."\n";578 $headers.= ' boundary="---='.$conf_mail['boundary_key'].'";'."\n";579 $headers.= ' reply-type=original'."\n";580 $headers.= 'MIME-Version: 1.0'."\n";581 $headers.= 'X-Mailer: Piwigo Mailer'."\n";582 583 // List on content-type584 571 $content_type_list[] = $args['email_format']; 585 572 if (!empty($conf_mail['alternative_email_format'])) … … 588 575 } 589 576 590 $content = '';577 $contents = array(); 591 578 592 579 foreach (array_unique($content_type_list) as $content_type) … … 607 594 $conf_mail[$cache_key]['theme']->assign( 608 595 array( 609 //Header610 'BOUNDARY_KEY' => $conf_mail['boundary_key'],611 'CONTENT_TYPE' => $content_type,612 'CONTENT_ENCODING' => get_pwg_charset(),613 614 // Footer615 596 'GALLERY_URL' => get_gallery_home_url(), 616 'GALLERY_TITLE' => 617 isset($page['gallery_title']) ? 618 $page['gallery_title'] : $conf['gallery_title'], 597 'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'], 619 598 'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', 620 599 'PHPWG_URL' => PHPWG_URL, 621 622 600 'TITLE_MAIL' => urlencode(l10n('A comment on your site')), 623 601 'MAIL' => get_webmaster_mail_address() 624 )); 602 ) 603 ); 625 604 626 605 if ($content_type == 'text/html') … … 641 620 642 621 // what are displayed on the header of each mail ? 643 $conf_mail[$cache_key]['header'] = 644 $conf_mail[$cache_key]['theme']->parse('mail_header', true); 622 $conf_mail[$cache_key]['header'] = $conf_mail[$cache_key]['theme']->parse('mail_header', true); 645 623 646 624 // what are displayed on the footer of each mail ? 647 $conf_mail[$cache_key]['footer'] = 648 $conf_mail[$cache_key]['theme']->parse('mail_footer', true); 625 $conf_mail[$cache_key]['footer'] = $conf_mail[$cache_key]['theme']->parse('mail_footer', true); 649 626 } 650 627 651 628 // Header 652 $content .= $conf_mail[$cache_key]['header'];629 $contents[$content_type] = $conf_mail[$cache_key]['header']; 653 630 654 631 // Content 655 632 if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html')) 656 633 { 657 $content .= '<p>'.634 $contents[$content_type].= '<p>'. 658 635 nl2br( 659 636 preg_replace("/(http:\/\/)([^\s,]*)/i", … … 665 642 { 666 643 // convert html text to plain text 667 $content .= strip_tags($args['content']);644 $contents[$content_type].= strip_tags($args['content']); 668 645 } 669 646 else 670 647 { 671 $content .= $args['content'];648 $contents[$content_type].= $args['content']; 672 649 } 673 650 674 651 // Footer 675 $content.= $conf_mail[$cache_key]['footer']; 676 677 // Close boundary 678 $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n"; 679 } 680 681 //~ // Close boundary 682 //~ $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n"; 683 684 // Undo Compute root_path in order have complete path 652 $contents[$content_type].= $conf_mail[$cache_key]['footer']; 653 } 654 655 // Undo Compute root_path in order have complete path 685 656 unset_make_full_url(); 686 657 687 return 688 trigger_event('send_mail', 689 false, /* Result */ 690 trigger_event('send_mail_to', get_strict_email_list($to)), 691 trigger_event('send_mail_subject', $cvt_subject), 692 trigger_event('send_mail_content', $content), 693 trigger_event('send_mail_headers', $headers), 694 $args 695 ); 696 } 697 698 /* 658 if (isset($contents['text/html'])) 659 { 660 $mail->isHTML(true); // Set email format to HTML 661 $mail->Body = $contents['text/html']; 662 663 if (isset($contents['text/plain'])) 664 { 665 $mail->AltBody = $contents['text/plain']; 666 } 667 } 668 else 669 { 670 $mail->isHTML(false); 671 $mail->Body = $contents['text/plain']; 672 } 673 674 if ($conf_mail['use_smtp']) 675 { 676 // now we need to split port number 677 if (strpos($conf_mail['smtp_host'], ':') !== false) 678 { 679 list($smtp_host, $smtp_port) = explode(':', $conf_mail['smtp_host']); 680 } 681 else 682 { 683 $smtp_host = $conf_mail['smtp_host']; 684 $smtp_port = 25; 685 } 686 687 $mail->IsSMTP(); 688 689 // enables SMTP debug information (for testing) 2 - debug, 0 - no message 690 $mail->SMTPDebug = 0; 691 692 $mail->Host = $smtp_host; 693 $mail->Port = $smtp_port; 694 695 if (!empty($conf_mail['smtp_secure']) and in_array($conf_mail['smtp_secure'], array('ssl', 'tls'))) 696 { 697 $mail->SMTPSecure = $conf_mail['smtp_secure']; 698 } 699 700 if (!empty($conf_mail['smtp_user'])) 701 { 702 $mail->SMTPAuth = true; 703 $mail->Username = $conf_mail['smtp_user']; 704 $mail->Password = $conf_mail['smtp_password']; 705 } 706 } 707 708 if(!$mail->send()) 709 { 710 // TODO use standard error 711 echo 'Message could not be sent.'; 712 echo 'Mailer Error: ' . $mail->ErrorInfo; 713 exit; 714 } 715 } 716 717 /* DEPRECATED 699 718 * pwg sendmail 700 719 * … … 708 727 * @return boolean (Ok or not) 709 728 */ 710 function pwg_send_mail($result, $to, $subject, $content , $headers)729 function pwg_send_mail($result, $to, $subject, $contents, $headers) 711 730 { 712 731 if (!$result) 713 732 { 733 include_once(PHPWG_ROOT_PATH.'include/class.phpmailer.php'); 734 714 735 global $conf_mail; 715 736 … … 724 745 else 725 746 { 726 if ($conf_mail['mail_options']) 727 { 728 $options = '-f '.$conf_mail['email_webmaster']; 729 return mail($to, $subject, $content, $headers, $options); 747 $mail = new PHPMailer; 748 749 $mail->From = 'plg@pigolabs.com'; 750 $mail->FromName = 'Pierrick en local'; 751 foreach (explode(',', $to) as $recipient) 752 { 753 $mail->addAddress($recipient); // Add a recipient 754 } 755 // $mail->addReplyTo('plg@piwigo.org', 'Pierrick de Piwigo.org'); 756 // $mail->addCC('cc@example.com'); 757 // $mail->addBCC('bcc@example.com'); 758 759 $mail->WordWrap = 76; // Set word wrap to 50 characters 760 761 if (isset($contents['text/html'])) 762 { 763 $mail->isHTML(true); // Set email format to HTML 764 $mail->Body = $contents['text/html']; 765 766 if (isset($contents['text/plain'])) 767 { 768 $mail->AltBody = $contents['text/plain']; 769 } 730 770 } 731 771 else 732 772 { 733 return mail($to, $subject, $content, $headers); 734 } 773 $mail->isHTML(false); 774 $mail->Body = $contents['text/plain']; 775 } 776 777 $mail->CharSet = 'UTF-8'; 778 $mail->Subject = $subject; 779 780 if(!$mail->send()) { 781 echo 'Message could not be sent.'; 782 echo 'Mailer Error: ' . $mail->ErrorInfo; 783 exit; 784 } 785 786 // if ($conf_mail['mail_options']) 787 // { 788 // $options = '-f '.$conf_mail['email_webmaster']; 789 // return mail($to, $subject, $content, $headers, $options); 790 // } 791 // else 792 // { 793 // return mail($to, $subject, $content, $headers); 794 // } 735 795 } 736 796 } … … 743 803 function move_ccs_rules_to_body($content) 744 804 { 805 return $content; 745 806 // We search all css rules in style tags 746 807 preg_match('#<style>(.*?)</style>#s', $content, $matches); -
trunk/themes/default/template/mail/text/html/header.tpl
r5125 r24951 1 -----={$BOUNDARY_KEY}2 Content-Type: {$CONTENT_TYPE}; charset="{$CONTENT_ENCODING}";3 Content-Transfer-Encoding: 8bit4 5 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 6 2 <html lang="{$lang_info.code}" dir="{$lang_info.direction}"> -
trunk/themes/default/template/mail/text/plain/header.tpl
r5095 r24951 1 -----={$BOUNDARY_KEY} 2 Content-Type: {$CONTENT_TYPE}; charset="{$CONTENT_ENCODING}"; 3 Content-Transfer-Encoding: 8bit{literal} 1 {literal} 4 2 5 3 {/literal}{*note that there must be an empty line to separate the mime headers*}
Note: See TracChangeset
for help on using the changeset viewer.