1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
*@author nicolaas [at] sunnysideup .co .nz |
5
|
|
|
* |
6
|
|
|
* |
7
|
|
|
**/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class TestIfEmailsAreWorking extends Controller |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
public function index($request) |
13
|
|
|
{ |
14
|
|
|
if (!Permission::check("ADMIN")) { |
15
|
|
|
return Security::permissionFailure($this); |
16
|
|
|
} |
17
|
|
|
$email = $request->requestVar($name = "email"); |
18
|
|
|
if ($email && Email::validEmailAddress($email)) { |
|
|
|
|
19
|
|
|
$number = rand(0, 10000); |
20
|
|
|
$from = Email::getAdminEmail(); |
|
|
|
|
21
|
|
|
$to = $email; |
22
|
|
|
$subject = "test mail ID".$number; |
23
|
|
|
$body = "test mail ID".$number; |
24
|
|
|
$htmlBody = "<h1>test mail ID".$number.'</h1>'; |
|
|
|
|
25
|
|
|
$basicMailOk = @mail($email, $subject, $body); |
26
|
|
|
if ($basicMailOk) { |
27
|
|
|
DB::alteration_message("basic mail (using the PHP mail function) has been sent with ID: ".$number, "created"); |
28
|
|
|
} else { |
29
|
|
|
DB::alteration_message("basic mail (using the PHP mail function) has * NOT * been sent with ID:".$number, "deleted"); |
30
|
|
|
} |
31
|
|
|
$e = new Email($from, $to, $subject, $body); |
32
|
|
|
if ($e->send()) { |
33
|
|
|
DB::alteration_message("standard Silverstripe email has been sent with ID: ".$number, "created"); |
34
|
|
|
} else { |
35
|
|
|
DB::alteration_message("standard Silverstripe email ***NOT*** has been sent with ID: ".$number, "deleted"); |
36
|
|
|
} |
37
|
|
|
//OR |
38
|
|
|
$e = new Email($from, $to, $subject, $body); |
39
|
|
|
if ($e->sendPlain()) { |
40
|
|
|
DB::alteration_message("plain text Silverstripe email has been sent with ID: ".$number, "created"); |
41
|
|
|
} else { |
42
|
|
|
DB::alteration_message("plain text Silverstripe email has ***NOT*** been sent with ID: ".$number, "deleted"); |
43
|
|
|
} |
44
|
|
|
} else { |
45
|
|
|
user_error("make sure to add a valid email - current one is '".$email."' (you can add the email like this: ".$request->getURL()."[email protected]", E_USER_WARNING); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.