Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: make it possible to send HTML email #3058

Merged
merged 4 commits into from
May 13, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions html/inc/email.inc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function send_email($user, $subject, $body, $body_html=null, $email_addr=null) {
if ($body_html) {
$mail->AltBody = $body;
$mail->Body = $body_html;
$mail->IsHTML(true);
} else {
$mail->Body = $body;
}
Expand All @@ -63,11 +64,16 @@ function send_email($user, $subject, $body, $body_html=null, $email_addr=null) {
} else if (defined('EMAIL_FROM')) {
$headers = "From: ". EMAIL_FROM;
}
if ($email_addr) {
return mail($email_addr, $subject, $body, $headers);
} else {
return mail($user->email_addr, $subject, $body, $headers);
if (!$email_addr) {
$email_addr = $user->email_addr;
}
if ($body_html) {
$body = "<html><body>\n";
$body = $body_html;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to append to the string on this line. At the moment this overwrites from the previous line.

$body .= "\n</body></html>\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
}
return mail($email_addr, $subject, $body, $headers);
}
}

Expand Down Expand Up @@ -179,7 +185,12 @@ function salted_key($key) {
return md5($key.'oogabooga');
}

function opt_out_url($user) {
return secure_url_base()."opt_out.php?code=".salted_key($user->authenticator)."&userid=$user->id";
function opt_out_url($user, $page="opt_out.php") {
return sprintf("%s%s?code=%s&userid=%d",
secure_url_base(),
$page,
salted_key($user->authenticator),
$user->id
);
}
?>