I have got the below script from this link. My Website is running with Digital Ocean hosting and I am unable to send a mail. Can you please help me out to work. Also, How do I get to know the actual mail failure ?
#!/usr/bin/php
<?php
if (PHP_SAPI !== 'cli') exit;
if (count($argv) < 4) {
echo 'Usage: ' . basename($_SERVER['PHP_SELF']) . ' <recipient1#recipient2#...> "<subject>" <"msg" or file>'."\n";
exit;
}
require_once "Mail.php";
$from = "xxx@gmail.com";
$aRecipients = (strpos($argv[1], '#')) ? explode('#', $argv[1]) : array($argv[1]);
$to = '';
foreach ($aRecipients as $recipient) $to .= "{$recipient},";
$to = rtrim($to, ',');
$subject = $argv[2];
$body = '';
if (file_exists($argv[3])) {
echo "[+] Delivering file {$argv[3]} to {$to}\n";
$body = file_get_contents($argv[3]);
} else {
$length = strlen($argv[3]);
echo "[+] Delivering text with length of {$length} to {$to}\n";
$body = "{$argv[3]}";
}
$host = gethostbyname('smtp.gmail.com');
$port = 465;
$username = "xxxx@gmail.com";
$password = "xxx";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp =& Mail::factory('smtp',
array(
'host' => $host,
'port' => $port,
'debug' => true, // set to true if u want to see what happens in the background
'auth' => true,
'username' => $username,
'password' => $password
)
);
$smtp->send($to, $headers, $body);
echo "[+] Mail sent :)\n";
?>