/
functions.php
63 lines (51 loc) · 1.82 KB
/
functions.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
<?php
function format_email($info, $format){
//set the root
$root = $_SERVER['DOCUMENT_ROOT'].'/template';
echo $root;
//grab the template content
$template = file_get_contents($root.'/signup_template.'.$format);
//replace all the tags
$template = ereg_replace('{USERNAME}', $info['username'], $template);
$template = ereg_replace('{EMAIL}', $info['email'], $template);
$template = ereg_replace('{KEY}', $info['key'], $template);
$template = ereg_replace('{SITEPATH}','http://52.2.223.106', $template);
//return the html of the template
return $template;
}
function send_email($info){
//format each email
$body = format_email($info,'html');
$body_plain_txt = format_email($info,'txt');
//setup the mailer
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message ->setSubject('Welcome to Geo Home For you');
$message ->setFrom(array('noreply@geomail.com' => 'Site Name'));
$message ->setTo(array($info['email'] => $info['username']));
$message ->setBody($body_plain_txt);
$message ->addPart($body, 'text/html');
echo "WHAT";
echo $message;
$result = $mailer->send($message);
return $result;
}
function show_errors($action){
$error = false;
if(!empty($action['result'])){
$error = "<ul class=\"alert $action[result]\">"."\n";
if(is_array($action['text'])){
//loop out each error
foreach($action['text'] as $text){
$error .= "<li><p>$text</p></li>"."\n";
}
}else{
//single error
$error .= "<li><p>$action[text]</p></li>";
}
$error .= "</ul>"."\n";
}
return $error;
}
?>