function smtp_mail

6.x smtp.module smtp_mail($to, $subject, $msg, $bool_html = FALSE, $attachments = array(), $bool_string_attachment = FALSE)
5.x smtp.module smtp_mail($to, $subject, $msg)
1 call to smtp_mail()
fp_mail in includes/misc.inc
Send an email. Drop-in replacement for PHP's mail() command, but can use SMTP protocol if enabled.
1 string reference to 'smtp_mail'
fp_mail in includes/misc.inc
Send an email. Drop-in replacement for PHP's mail() command, but can use SMTP protocol if enabled.

File

modules/smtp/smtp.module, line 111
This is the main module file for SMTP, which will let us send emails using SMTP instead of PHP's mail() command.

Code

function smtp_mail($to, $subject, $msg) {

  $system_path = trim($GLOBALS ["fp_system_settings"]["file_system_path"]);
  require_once ("$system_path/inc/PHPMailer/src/Exception.php");
  require_once ("$system_path/inc/PHPMailer/src/PHPMailer.php");
  require_once ("$system_path/inc/PHPMailer/src/SMTP.php");

  $mail = new PHPMailer();

  // Settings
  $mail->IsSMTP();
  $mail->CharSet = 'UTF-8';

  $mail->Host = variable_get('smtp_host', '');
  $mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
  // 0 = no output, 1 = errors and messages, 2 = messages only.

  $mail->SMTPSecure = variable_get('smtp_secure', ''); // tls, ssl, and none are allowed.

  $mail->SMTPAuth = true; // enable SMTP authentication
  $mail->Port = variable_get('smtp_port', ''); // set the SMTP port
  $mail->Username = variable_get('smtp_username', '');
  $mail->Password = variable_get('smtp_password', ''); // SMTP account password example

  // Content
  //$mail->isHTML(true);                                  // Set email format to HTML
  //$mail->Subject = 'Here is the subject';
  //$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
  //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

  // Content
  $mail->Subject = $subject;
  $mail->Body = $msg;

  $mail->setFrom(variable_get('smtp_from_email_address', 'noreply@yourdomain.com'), variable_get('smtp_from_email_name', 'NoReply - FlightPath'));


  //Recipients
  $temp = explode(',', $to);
  foreach ($temp as $line) {
    $line = trim($line);
    if ($line != "") {
      $mail->addAddress($line); // Add a recipient    
    }
  }


  //$mail->addAddress('ellen@example.com', 'Ellen Smith');               // Name is optional
  //$mail->addReplyTo('info@example.com', 'Information');
  //$mail->addCC('cc@example.com');
  //$mail->addBCC('bcc@example.com');  


  $x = $mail->send();
  if (!$x) {
    fpm("PHPMailer error: " . $mail->ErrorInfo);
    // TODO:  Log error?
  }



}