-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.php
108 lines (78 loc) · 2.71 KB
/
email.php
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
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));
$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
$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;
if($values["cc"] == "Y") {
$copy = "\r\nCc:". $cUser->person[0]->email;
}
else {
$copy = "";
}
if(known_email_addressp($_REQUEST["email_to"])) {
$mailed = mail($_REQUEST["email_to"], SITE_SHORT_TITLE .": ". $values["subject"], wordwrap($values["message"], 64), "From:". $cUser->person[0]->email . $copy);
}
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;
}
}
?>