isSMTP(); //Enable SMTP debugging // SMTP::DEBUG_OFF = off (for production use) // SMTP::DEBUG_CLIENT = client messages // SMTP::DEBUG_SERVER = client and server messages $mail->SMTPDebug = SMTP::DEBUG_OFF; //Set the hostname of the mail server $mail->Host = 'smtp.gmail.com'; //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission $mail->Port = 587; //Set the encryption mechanism to use - STARTTLS or SMTPS $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Whether to use SMTP authentication $mail->SMTPAuth = true; //Username to use for SMTP authentication - use full email address for gmail $mail->Username = $config_array->{"gmail_username"}; //Password to use for SMTP authentication $mail->Password = $config_array->{"gmail_password"}; //Set who the message is to be sent from $mail->setFrom($config_array->{"gmail_username"}, 'Food Inventory'); //Set an alternative reply-to address $mail->addAddress($to, $to_first_name . " " . $to_last_name); //Set the subject line $mail->Subject = $subject; $mail->Body = $body; //Replace the plain text body with one created manually $mail->AltBody = $alt_body; //send the message, check for errors return ($mail->send()); } catch (Exception $e) { return false; } }