-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendgmail.php
More file actions
executable file
·50 lines (43 loc) · 1.29 KB
/
sendgmail.php
File metadata and controls
executable file
·50 lines (43 loc) · 1.29 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
#!/usr/bin/php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if( count( $argv ) != 7 ) {
echo $argv[0].": Could not parse arguments\n";
echo "Usage:\n";
echo $argv[0]." <smtp username> <smtp password> <to email address> <to email name>\n";
echo " <subject> <email body content>\n";
exit(1);
}
$username = $argv[1];
$password = $argv[2];
$to_email = $argv[3];
$to_name = $argv[4];
$subject = $argv[5];
$bodytext = $argv[6];
try {
require 'phpMailer/src/Exception.php';
require 'phpMailer/src/PHPMailer.php';
require 'phpMailer/src/SMTP.php';
$mail = new PHPMailer(true);
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = $username;
$mail->Password = $password;
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->addAddress( $to_email, $to_name );
$mail->setFrom( $username, 'Nagios');
$mail->isHTML(false);
$mail->Subject = $subject;
$mail->Body = str_replace('\n',"\n", $bodytext);
$mail->send();
exit(0);
} catch (Exception $e) {
echo 'Message could not be sent.'."\n";
echo 'Mailer Error: ' . $mail->ErrorInfo."\n";
print_r($e);
exit(1);
}