0, 'msg' => 'Parameter tidak lengkap'], 422); } if(isset($_POST['from'])){ $from = $_POST['from']; }else{ $from = "system@spota.untan.ac.id"; } $toArr = json_decode($to, 1); $emailTujuan = ''; if (is_array($toArr) && sizeof($toArr) > 0) { $emailTujuan = implode(', ', $toArr); } else { jsonResponse(['status' => 0, 'msg' => 'Penerima email tidak valid'], 422); } $headers = 'MIME-Version: 1.0'."\r\n"; $headers .= 'Content-type:text/html;charset=UTF-8'."\r\n"; $headers .= "From: $from"; $result = mail($emailTujuan, $judul, $content, $headers); echo json_encode([ 'status' => $result ? 1 : 0, 'msg' => $result ? 'Message has been sent' : 'Message could not be sent', ]); // 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; // Enable SMTP authentication // $mail->SMTPDebug = 4; // //gmail // $mail->Username = 'spota.ifuntan@gmail.com'; // SMTP username // $mail->Password = 'Steven123!@#'; // SMTP password // $mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` abov // $mail->SMTPOptions = array( // 'ssl' => array( // 'verify_peer' => false, // 'verify_peer_name' => false, // 'allow_self_signed' => true, // ), // ); // $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged // //Recipients // $mail->setFrom('spota.ifuntan@gmail.com', 'SPOTA IF UNTAN'); // $mail->addReplyTo('spota.ifuntan@gmail.com', 'SPOTA IF UNTAN'); // $toArr = json_decode($to, 1); // if (sizeof($toArr) > 0) { // for ($i = 0; $i < sizeof($toArr); ++$i) { // if ($i === 0) { // $mail->addAddress($toArr[$i], ''); // Add a recipient // } else { // $mail->addCC($toArr[$i]); // } // } // } else { // exit(); // } // //$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'; // $mail->send(); // //echo 'Message has been sent'; // } catch (Exception $e) { // //echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; // }