#!/usr/local/bin/php
<?php
if( !isset($argv[1]) ){
  print "\nUsage: testPHPMail.sh <Account Number> \n\n";
  exit;
}

/*
Does not work on GoDaddy!

composer require phpmailer/phpmailer
mv vendor /usr/share/php
php PHPMailer.php (works!)
*/

// while signed in to gmail account go to https://www.google.com/settings/security/lesssecureapps and turn ON

  require "vendor/autoload.php";
  use PHPMailer\PHPMailer\PHPMailer;
  use PHPMailer\PHPMailer\Exception;

  switch ($argv[1]) {
    case 1:
      $host="smtp.lusfiber.net";
      $usr="cbsnow@lusfiber.net";
      $pswd="CCbbss11";
      break;
    case 2:
      $host="smtp.gmail.com";
      $usr="analyticsuulala@gmail.com";
      $pswd="uulala11";
      break;
    case 3:
      $host="mail.sparkacadiana.org";
      $usr="bruce@sparkacadiana.org";
      $pswd="CCbbss11";
       break;
    default:
       print "Account Number is too large!\n";
       exit;
  }//end switch
//print "host=$host, usr=$usr, pswd=$pswd\n";

  $recip="testPHPMail@brucesnow.us";
  $subj="testPHPMail by $usr@$host ON INMOTION sparka10";
  $msg="testPHPMail by $usr@$host";
  $sender="PHPMailer@brucesnow.us";
  $alias="PHPMailer"; //sender alias
//exit;

  $developmentMode = true;
  $mailer = new PHPMailer($developmentMode);

  try {
    $mailer->SMTPDebug = 0;
    $mailer->isSMTP();

    if ($developmentMode) {
      $mailer->SMTPOptions = [
        'ssl'=> [
          'verify_peer' => false,
          'verify_peer_name' => false,
          'allow_self_signed' => true
        ]
      ];
    }//end if developmentMode
    $mailer->SMTPAuth = true;

    $mailer->Host = $host; 
    $mailer->Username = $usr;
    $mailer->Password = $pswd;
    $mailer->SMTPSecure = 'tls';
    $mailer->Port = 587;

    $mailer->setFrom($sender,$alias);

    $ARR=explode(",",$recip);
    for ($i=0;$i<sizeof($ARR);$i++){
      $mailer->addAddress($ARR[$i], 'Name of recipient');
    }//end for

    $mailer->isHTML(true);
    $mailer->Subject = $subj;
    $mailer->Body = $msg;

    $mailer->send();
    $mailer->ClearAllRecipients();
    print "test email sent by $usr@$host.";

  } catch (Exception $e) {
    print "SENDING $usr@$host FAILED. INFO: " . $mailer->ErrorInfo;
  }//end try/catch
?>

