Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
049667fc
Commit
049667fc
authored
12 years ago
by
Peter Rotich
Browse files
Options
Downloads
Patches
Plain Diff
Switch over to the new mailer class
parent
1a33dc3e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/class.email.php
+6
-112
6 additions, 112 deletions
include/class.email.php
include/class.upgrader.php
+1
-1
1 addition, 1 deletion
include/class.upgrader.php
main.inc.php
+2
-1
2 additions, 1 deletion
main.inc.php
with
9 additions
and
114 deletions
include/class.email.php
+
6
−
112
View file @
049667fc
...
...
@@ -141,87 +141,15 @@ class Email {
}
function
send
(
$to
,
$subject
,
$message
,
$attachments
=
null
,
$options
=
null
)
{
global
$cfg
,
$ost
;
//Get SMTP info IF enabled!
$smtp
=
array
();
if
(
$this
->
isSMTPEnabled
()
&&
(
$info
=
$this
->
getSMTPInfo
()))
{
//is SMTP enabled for the current email?
$smtp
=
$info
;
}
elseif
(
$cfg
&&
(
$email
=
$cfg
->
getDefaultSMTPEmail
())
&&
$email
->
isSMTPEnabled
())
{
//What about global SMTP setting?
if
(
$email
->
allowSpoofing
()
&&
(
$info
=
$email
->
getSMTPInfo
()))
//If spoofing is allowed..then continue.
$smtp
=
$info
;
elseif
(
$email
->
getId
()
!=
$this
->
getId
())
//No spoofing allowed. Send it via the default SMTP email.
return
$email
->
send
(
$to
,
$subject
,
$message
,
$attachments
,
$options
);
}
//Get the goodies
require_once
(
'Mail.php'
);
// PEAR Mail package
require_once
(
'Mail/mime.php'
);
// PEAR Mail_Mime packge
//do some cleanup
$eol
=
"
\n
"
;
$to
=
preg_replace
(
"/(
\r\n
|
\r
|
\n
)/s"
,
''
,
trim
(
$to
));
$subject
=
stripslashes
(
preg_replace
(
"/(
\r\n
|
\r
|
\n
)/s"
,
''
,
trim
(
$subject
)));
$body
=
stripslashes
(
preg_replace
(
"/(
\r\n
|
\r
)/s"
,
"
\n
"
,
trim
(
$message
)));
$fromname
=
$this
->
getName
();
$from
=
sprintf
(
'"%s"<%s>'
,(
$fromname
?
$fromname
:
$this
->
getEmail
()),
$this
->
getEmail
());
$headers
=
array
(
'From'
=>
$from
,
'To'
=>
$to
,
'Subject'
=>
$subject
,
'Date'
=>
date
(
'D, d M Y H:i:s O'
),
'Message-ID'
=>
'<'
.
Misc
::
randCode
(
6
)
.
''
.
time
()
.
'-'
.
$this
->
getEmail
()
.
'>'
,
'X-Mailer'
=>
'osTicket v1.7'
,
'Content-Type'
=>
'text/html; charset="UTF-8"'
);
$mime
=
new
Mail_mime
();
$mime
->
setTXTBody
(
$body
);
//XXX: Attachments
if
(
$attachments
){
foreach
(
$attachments
as
$attachment
)
{
if
(
$attachment
[
'file_id'
]
&&
(
$file
=
AttachmentFile
::
lookup
(
$attachment
[
'file_id'
])))
$mime
->
addAttachment
(
$file
->
getData
(),
$file
->
getType
(),
$file
->
getName
(),
false
);
elseif
(
$attachment
[
'file'
]
&&
file_exists
(
$attachment
[
'file'
])
&&
is_readable
(
$attachment
[
'file'
]))
$mime
->
addAttachment
(
$attachment
[
'file'
],
$attachment
[
'type'
],
$attachment
[
'name'
]);
}
}
$options
=
array
(
'head_encoding'
=>
'quoted-printable'
,
'text_encoding'
=>
'quoted-printable'
,
'html_encoding'
=>
'base64'
,
'html_charset'
=>
'utf-8'
,
'text_charset'
=>
'utf-8'
);
//encode the body
$body
=
$mime
->
get
(
$options
);
//encode the headers.
$headers
=
$mime
->
headers
(
$headers
);
if
(
$smtp
)
{
//Send via SMTP
$mail
=
mail
::
factory
(
'smtp'
,
array
(
'host'
=>
$smtp
[
'host'
],
'port'
=>
$smtp
[
'port'
],
'auth'
=>
$smtp
[
'auth'
]
?
true
:
false
,
'username'
=>
$smtp
[
'username'
],
'password'
=>
$smtp
[
'password'
],
'timeout'
=>
20
,
'debug'
=>
false
,
));
$result
=
$mail
->
send
(
$to
,
$headers
,
$body
);
if
(
!
PEAR
::
isError
(
$result
))
return
true
;
//SMTP failed - log error.
$alert
=
sprintf
(
"Unable to email via %s:%d [%s]
\n\n
%s
\n
"
,
$smtp
[
'host'
],
$smtp
[
'port'
],
$smtp
[
'username'
],
$result
->
getMessage
());
$ost
->
logError
(
'SMTP Error'
,
$alert
,
false
);
//NOTE: email alert overwrite - don't email when having email trouble.
//print_r($result);
}
//No SMTP or it failed....use php's native mail function.
$mail
=
mail
::
factory
(
'mail'
);
return
PEAR
::
isError
(
$mail
->
send
(
$to
,
$headers
,
$body
))
?
false
:
true
;
$mailer
=
new
Mailer
(
$this
);
if
(
$attachments
)
$mailer
->
addAttachments
(
$attachments
)
;
return
$mailer
->
send
(
$to
,
$subject
,
$message
,
$options
);
}
function
update
(
$vars
,
&
$errors
)
{
$vars
=
$vars
;
$vars
[
'cpasswd'
]
=
$this
->
getPasswd
();
//Current decrypted password.
...
...
@@ -254,42 +182,8 @@ class Email {
/******* Static functions ************/
//sends emails using native php mail function Email::sendmail( ......);
//Don't use this function if you can help it.
function
sendmail
(
$to
,
$subject
,
$message
,
$from
)
{
require_once
(
'Mail.php'
);
// PEAR Mail package
require_once
(
'Mail/mime.php'
);
// PEAR Mail_Mime packge
$eol
=
"
\n
"
;
$to
=
preg_replace
(
"/(
\r\n
|
\r
|
\n
)/s"
,
''
,
trim
(
$to
));
$subject
=
stripslashes
(
preg_replace
(
"/(
\r\n
|
\r
|
\n
)/s"
,
''
,
trim
(
$subject
)));
$body
=
stripslashes
(
preg_replace
(
"/(
\r\n
|
\r
)/s"
,
"
\n
"
,
trim
(
$message
)));
$headers
=
array
(
'From'
=>
$from
,
'To'
=>
$to
,
'Subject'
=>
$subject
,
'Message-ID'
=>
'<'
.
Misc
::
randCode
(
10
)
.
''
.
time
()
.
'@osTicket>'
,
'X-Mailer'
=>
'osTicket v 1.6'
,
'Content-Type'
=>
'text/html; charset="UTF-8"'
);
$mime
=
new
Mail_mime
();
$mime
->
setTXTBody
(
$body
);
$options
=
array
(
'head_encoding'
=>
'quoted-printable'
,
'text_encoding'
=>
'quoted-printable'
,
'html_encoding'
=>
'base64'
,
'html_charset'
=>
'utf-8'
,
'text_charset'
=>
'utf-8'
);
//encode the body
$body
=
$mime
->
get
(
$options
);
//headers
$headers
=
$mime
->
headers
(
$headers
);
$mail
=
mail
::
factory
(
'mail'
);
return
PEAR
::
isError
(
$mail
->
send
(
$to
,
$headers
,
$body
))
?
false
:
true
;
}
function
getIdByEmail
(
$email
)
{
function
getIdByEmail
(
$email
)
{
$sql
=
'SELECT email_id FROM '
.
EMAIL_TABLE
.
' WHERE email='
.
db_input
(
$email
);
if
((
$res
=
db_query
(
$sql
))
&&
db_num_rows
(
$res
))
...
...
This diff is collapsed.
Click to expand it.
include/class.upgrader.php
+
1
−
1
View file @
049667fc
...
...
@@ -69,7 +69,7 @@ class Upgrader extends SetupWizard {
if
(
$email
)
{
$email
->
send
(
$thistaff
->
getEmail
(),
$subject
,
$error
);
}
else
{
//no luck - try the system mail.
Em
ail
::
sendmail
(
$thistaff
->
getEmail
(),
$subject
,
$error
,
sprintf
(
'"osTicket Alerts"<%s>'
,
$thistaff
->
getEmail
()));
M
ail
er
::
sendmail
(
$thistaff
->
getEmail
(),
$subject
,
$error
,
sprintf
(
'"osTicket Alerts"<%s>'
,
$thistaff
->
getEmail
()));
}
}
...
...
This diff is collapsed.
Click to expand it.
main.inc.php
+
2
−
1
View file @
049667fc
...
...
@@ -109,6 +109,7 @@
require
(
INCLUDE_DIR
.
'class.nav.php'
);
require
(
INCLUDE_DIR
.
'class.format.php'
);
//format helpers
require
(
INCLUDE_DIR
.
'class.validator.php'
);
//Class to help with basic form input validation...please help improve it.
require
(
INCLUDE_DIR
.
'class.mailer.php'
);
require
(
INCLUDE_DIR
.
'mysql.php'
);
#CURRENT EXECUTING SCRIPT.
...
...
@@ -178,7 +179,7 @@
if
(
$ferror
)
{
//Fatal error
//try alerting admin using email in config file
$msg
=
$ferror
.
"
\n\n
"
.
THISPAGE
;
Em
ail
::
sendmail
(
ADMIN_EMAIL
,
'osTicket Fatal Error'
,
$msg
,
sprintf
(
'"osTicket Alerts"<%s>'
,
ADMIN_EMAIL
));
M
ail
er
::
sendmail
(
ADMIN_EMAIL
,
'osTicket Fatal Error'
,
$msg
,
sprintf
(
'"osTicket Alerts"<%s>'
,
ADMIN_EMAIL
));
//Display generic error to the user
die
(
"<b>Fatal Error:</b> Contact system administrator."
);
exit
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment