Commit e39047b6 authored by David Anderson's avatar David Anderson

web: make "email friends" feature work without project configuration

Previously the feature that lets people send email about the project
to their friends only worked if the project supplied a message.
Remove this restriction; supply a default message.
Also make it work with or without PHPMailer.

Projects can still supply a default subject and message;
the user can now edit these.

Remove the ability to send HTML email
and to macro-substitute names in the message.
parent 40a630e5
......@@ -16,91 +16,44 @@
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once("../project/project.inc");
require_once("../inc/email.inc");
function replace($toname, $comment, $fromname, $template) {
$pat = array(
'/<toname\/>/',
'/<comment\/>/',
'/<fromname\/>/',
);
$rep = array(
$toname,
$comment,
$fromname,
);
return preg_replace($pat, $rep, $template);
}
$html = file_get_contents('../ops/ffmail/html');
$text = file_get_contents('../ops/ffmail/text');
$subject = file_get_contents('../ops/ffmail/subject');
$preview = get_str('preview', true);
$uname = get_str('uname');
$uemail = get_str('uemail');
$comment = get_str('comment', true);
$text = get_str('text');
$subject = get_str('subject');
$action = get_str('action');
if ($action=='Preview') {
page_head(tra("Email preview"));
echo tra("Your email will appear as follows:")."
<hr>
";
echo replace("[Friend's name]", $comment, $uname, $html);
$args = strstr($_SERVER['REQUEST_URI'], '?');
$args = str_replace('action=Preview', 'action=Send', $args);
$user = get_logged_in_user();
echo "
<hr>
<b><a href=ffmail_action.php$args>".tra("Send email")."</a></b>
<p>
[".tra("Use your browser's back button to return to message form")."]
";
page_tail();
} else {
page_head(tra("Sending emails"));
$found = false;
for ($i=0; $i<5; $i++) {
$n = get_str("n$i", true);
$e = get_str("e$i", true);
if ($n && $e) {
$html_body = replace($n, $comment, $uname, $html);
$text_body = replace($n, $comment, $uname, $text);
$found = true;
if (function_exists("make_php_mailer")) {
$mail = make_php_mailer();
$mail->AddAddress($e, $n);
$mail->Subject = $subject;
if ($html) {
$mail->Body = $html_body;
$mail->AltBody = $text_body;
} else {
$mail->Body = replace($n, $comment, $uname, $text);
}
$mail->From = $uemail;
$mail->FromName = $uname;
if (!$mail->Send()) {
echo "<br>".tra("failed to send email to %1: %2", $e, $mail->ErrorInfo)."\n";
continue;
}
} else {
if (!mail($e, $subject, $text_body, "$uname <$uemail>")) {
echo "<br>".tra("failed to send email to %1", $e)."\n";
}
}
echo "<br>".tra("email sent successfully to %1", $e)."\n";
page_head(tra("Sending emails"));
$found = false;
for ($i=0; $i<6; $i++) {
$e = get_str("e$i", true);
if (!$e) continue;
$found = true;
if (function_exists("make_php_mailer")) {
require_once("../inc/phpmailer/class.phpmailer.php");
$mail = make_php_mailer();
$mail->AddAddress($e);
$mail->Subject = $subject;
$mail->Body = $text;
$mail->From = $user->email_addr;
$mail->FromName = $user->name;
if (!$mail->Send()) {
echo "<br>".tra("failed to send email to %1: %2", $e, $mail->ErrorInfo)."\n";
continue;
}
}
if ($found) {
echo "
<p>".tra("Thanks for telling your friends about %1", PROJECT);
} else {
echo tra("You forgot to enter your friends' names and/or email addresses; Please %1return to the form%2 and enter them.", "<a href=ffmail_form.php>", "</a>");
if (!mail($e, $subject, $text, "From: $user->name <$user->email_addr>")) {
echo "<br>".tra("failed to send email to %1", $e)."\n";
}
}
page_tail();
echo "<br>".tra("email sent successfully to %1", $e)."\n";
}
if ($found) {
echo "
<p>".tra("Thanks for telling your friends about %1", PROJECT);
} else {
echo tra("You forgot to enter email addresses; Please %1return to the form%2 and enter them.", "<a href=ffmail_form.php>", "</a>");
}
page_tail();
exit();
?>
......@@ -22,45 +22,38 @@
require_once("../inc/util.inc");
check_get_args(array());
$master_url = parse_config(get_config(), "<master_url>");
$user = get_logged_in_user();
if (!@file_get_contents('../ops/ffmail/subject')) {
error_page(tra("This project hasn't created an email message - please notify its administrators"));
}
page_head(tra("Tell your friends about %1", PROJECT));
echo "
<table width=600><tr><td>
".tra("Help us by telling your friends, family and coworkers about %1", PROJECT)."
<p>
".tra("Fill in this form with the names and email addresses of people you think might be interested in %1. We'll send them an email in your name, and you can add your own message if you like.", PROJECT)."
<form method=get action=ffmail_action.php>
<table cellpadding=4>
<tr><th>".tra("Your name:")."</th><th>".tra("Your email address:")."</th></tr>
<tr><td><b>$user->name</b></td><td><b>$user->email_addr</b></td></tr>
<input type=hidden name=uname value=\"$user->name\">
<input type=hidden name=uemail value=\"$user->email_addr\">
$text = @file_get_contents('../ops/ffmail/text');
if (!$text) {
$text = "I'm using my computer to crunch numbers for a science project called ".PROJECT.". The more computers participate, the more science gets done. Would you like to join me?
<tr><th>".tra("Friend's name:")."</th><th>".tra("Friend's email address:")."</th></tr>
To learn how, visit $master_url
";
for ($i=0; $i<5; $i++) {
echo "
<tr><td><input size=30 name=n$i></td><td><input size=30 name=e$i></tr>
";
}
echo "
<tr><th colspan=2>".tra("Additional message (optional)")."</th></tr>
<tr><td colspan=2><textarea name=comment rows=8 cols=50></textarea></td></tr>
<tr><td align=center><input class=\"btn btn-default\" type=submit name=action value=".tra("Preview")."></td>
<td align=center><input class=\"btn btn-primary\" type=submit name=action value=".tra("Send")."></td>
</tr>
</table>
</form>
</td></tr></table>
";
$text .= "\n$user->name";
$subject = @file_get_contents('../ops/ffmail/subject');
if (!$subject) {
$subject = "Join me at ".PROJECT;
}
echo tra("Use this form to send email messages to people you think might be interested in %1.", PROJECT);
echo "<p><form method=get action=ffmail_action.php>\n";
start_table();
row2("From:", "$user->name &lt;$user->email_addr>");
for ($i=0; $i<6; $i++) {
row2(tra("To:"), "<input size=30 name=e$i>");
}
row2(tra("Subject"), "<input size=80 name=subject value=\"$subject\">");
row2(tra("Message"), "<textarea name=text rows=8 cols=50>$text</textarea>");
row2("", "<input class=\"btn btn-primary\" type=submit name=action value=".tra("Send").">");
end_table();
echo "</form>\n";
page_tail();
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment