-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-email.php
47 lines (40 loc) · 1.35 KB
/
get-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
<?php
// Applications can call this file with a Composr username to find out that user's email address.
// They should expect a string with a single email address in return.
// One input is required when calling this file.
$input_username = $argv[1];
// Configure a MySQL/MariaDB account with read access to Composr's cms_f_members table here.
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Connect via SSL/TLS.
$pdo_options = [
PDO::MYSQL_ATTR_SSL_CA => '',
PDO::MYSQL_ATTR_SSL_CERT => '',
PDO::MYSQL_ATTR_SSL_KEY => '',
];
// Get the email address of the Composr user with the provided username.
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password, $pdo_options);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT m_email_address FROM cms_f_members WHERE m_username = :input_username");
$stmt->bindParam(":input_username", $input_username, PDO::PARAM_STR);
if($stmt->execute()) {
if($stmt->rowCount() == 1){
if($row = $stmt->fetch()){
$email_address = $row["m_email_address"];
}
}
}
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
// Return the email address, or a placeholder if one was not found.
if (!empty($email_address)) {
echo $email_address;
} else {
echo "[email protected]";
}
?>