0, 'msg' => 'Parameter tidak lengkap'], 422); } if (isset($_POST['from'])) { $from = $_POST['from']; $fromText = $from; } else { $from = 'system@spota.untan.ac.id'; $fromText = 'SPOTA Informatika UNTAN'; } try { //Server settings //$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output $mail->isSMTP(); // Send using SMTP $mail->Host = (string) (getenv('SPOTA_SMTP_HOST') ?: 'smtp.gmail.com'); $mail->SMTPAuth = true; $mail->SMTPDebug = 0; //$mail->SMTPSecure = 'tls'; // Enable SMTP authentication //gmail // $mail->Username = 'mail.informatika.untan@gmail.com'; // SMTP username // $mail->Password = 'informatikauntan247mail'; // SMTP password $mail->Username = (string) (getenv('SPOTA_SMTP_USERNAME') ?: 'tu1@informatika.untan.ac.id'); $mail->Password = (string) (getenv('SPOTA_SMTP_PASSWORD') ?: 'IFuntanpnk-2020'); $mail->Port = (int) (getenv('SPOTA_SMTP_PORT') ?: 587); $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged // $mail->SMTPOptions = [ // 'ssl' => [ // 'verify_peer' => false, // 'verify_peer_name' => false, // 'allow_self_signed' => true, // ], // ]; //Recipients $mail->setFrom($from, $fromText); $toArr = json_decode($to, 1); if (!is_array($toArr) || empty($toArr)) { jsonResponse(['status' => 0, 'msg' => 'Penerima email tidak valid'], 422); } foreach ($toArr as $key => $val) { $mail->addAddress(trim($val), $val); // Add a recipient } //$mail->addReplyTo('info@example.com', 'Information'); //$mail->addCC('cc@example.com'); //$mail->addBCC('bcc@example.com'); // Attachments //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name // Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = $judul; $mail->Body = $content; //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if ($mail->send()) { echo json_encode(['status' => 1, 'msg' => 'Message has been sent']); } else { echo json_encode(['status' => 0, 'msg' => 'Mailer Error: '.$mail->ErrorInfo]); } //; } catch (Exception $e) { echo json_encode(['status' => 0, 'msg' => "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"]); } // try { // //Server settings // //$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output // $mail->isSMTP(); // Send using SMTP // $mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through // $mail->SMTPAuth = true; // $mail->SMTPDebug = 4; // //$mail->SMTPSecure = 'tls'; // Enable SMTP authentication // //gmail // $mail->Username = 'mail.informatika.untan@gmail.com'; // SMTP username // $mail->Password = 'informatikauntan247mail'; // SMTP password // $mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` abov // $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged // // $mail->SMTPOptions = [ // // 'ssl' => [ // // 'verify_peer' => false, // // 'verify_peer_name' => false, // // 'allow_self_signed' => true, // // ], // // ]; // //Recipients // $mail->setFrom($from, $fromText); // $toArr = json_decode($to, 1); // foreach ($toArr as $key => $val) { // $mail->addAddress(trim($val), $val); // Add a recipient // } // //$mail->addReplyTo('info@example.com', 'Information'); // //$mail->addCC('cc@example.com'); // //$mail->addBCC('bcc@example.com'); // // Attachments // //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments // //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name // // Content // $mail->isHTML(true); // Set email format to HTML // $mail->Subject = $judul; // $mail->Body = $content; // //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; // if ($mail->send()) { // echo 'Message has been sent'; // } else { // echo 'error message'; // echo 'Mailer Error: '.$mail->ErrorInfo; // } // //; // } catch (Exception $e) { // echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; // }