forked from lastorset/Local-Exchange
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathemail.php
More file actions
108 lines (89 loc) · 3.52 KB
/
Copy pathemail.php
File metadata and controls
108 lines (89 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/* changes by ejkv
If site SAFE mode = on? =>> Pear::(mail) using the 5th mail parameter causes error by sending mail - added by ejkv
If SAFE_mode_ON is set true (inc.config.php), in email.php no CC: will be sent, nor will CC: selection be showed in UI
*/
include_once("includes/inc.global.php");
$p->site_section = SECTION_EMAIL;
$p->page_title = _("Email a Member");
$cUser->MustBeLoggedOn();
include("includes/inc.forms.php");
//
// First, we define the form
//
$form->addElement("hidden", "email_to", $_REQUEST["email_to"]);
$form->addElement("hidden", "member_to", $_REQUEST["member_to"]);
$member_to = new cMember;
$member_to->LoadMember($_REQUEST["member_to"]);
$form->addElement("static", null, _("To").": <I>". $_REQUEST["email_to"] . " (". $member_to->member_id .")</I>");
$form->addElement("text", "subject", _("Subject").": ", array('size' => 35, 'maxlength' => 100));
if (!SAFE_MODE_ON) $form->addElement("select", "cc", _("Would you like to receive a copy?"), array("Y"=>_("Yes"), "N"=>_("No"))); // - changed by ejkv
// $form->addElement("select", "cc", _("Would you like to receive a copy?"), array("Y"=>_("Yes"), "N"=>_("No")));
/* The following code should work, and works on my server, but not on Open Access. Bug?
$cc[] =& HTML_QuickForm::createElement('radio',null,null,'<FONT SIZE=2>Yes</FONT>','Y');
$cc[] =& HTML_QuickForm::createElement('radio',null,null,'<FONT SIZE=2>No</FONT>','N');
$form->addGroup($cc, "cc", 'Would you like to recieve a copy?');
*/
$form->addElement("static", null, null, null);
$form->addElement("textarea", "message", _("Your Message"), array("cols"=>65, "rows"=>10, "wrap"=>"soft"));
$form->addElement("static", null, null, null);
$form->addElement("submit", "btnSubmit", _("Send"));
//
// Define form rules
//
$form->addRule("message", _("Enter your message"), "required");
if ($form->validate()) { // Form is validated so processes the data
$form->freeze();
$form->process("process_data", false);
} else { // Display the form
if (!SAFE_MODE_ON) $form->setDefaults(array("cc"=>"Y")); // - changed by ejkv
// $form->setDefaults(array("cc"=>"Y"));
$p->DisplayPage($form->toHtml());
}
//
// The form has been submitted with valid data, so process it
//
function process_data ($values) {
global $p, $cUser;
$headers = "From:". $cUser->person[0]->email ."\nContent-type: text/plain; charset=UTF-8";
$body = wordwrap($values["message"], 64);
if($values["cc"] == "Y") {
$headers .= "\r\nCc: ". $cUser->person[0]->email;
}
if(known_email_addressp($_REQUEST["email_to"])) {
// added SAFE_MODE check, and removed 5th parameter, if safe mode = ON - by ejkv
if (SAFE_MODE_ON) {
$mailed = mail($_REQUEST["email_to"], SITE_SHORT_TITLE .": ". $values["subject"], $body, $headers);
}
else {
$mailed = mail($_REQUEST["email_to"], SITE_SHORT_TITLE .": ". $values["subject"], $body, $headers, $cUser->person[0]->email);
}
}
else {
$mailed = false;
}
if($mailed) {
$output = _("Your message has been sent.");
}
else {
$output = _("There was a problem sending the email.")." "._("Please try again later.");
}
$p->DisplayPage($output);
}
/**
* Checks whether the given email address exists in the database.
*/
function known_email_addressp($email) {
global $cDB;
$email = $cDB->EscTxt($email);
$sql = "SELECT person_id FROM " . DATABASE_PERSONS .
" WHERE email = $email";
$r = $cDB->Query($sql);
if($row = mysql_fetch_array($r)) {
return true;
}
else {
return false;
}
}
?>