['sms' => '@txt.att.net', 'mms' => '@mms.att.net'], 'verizon' => ['sms' => '@vtext.com', 'mms' => '@vzwpix.com'], 'tmobile' => ['sms' => '@tmomail.net', 'mms' => '@tmomail.net'], 'sprint' => ['sms' => '@messaging.sprintpcs.com', 'mms' => '@pm.sprint.com'], 'boost' => ['sms' => '@sms.myboostmobile.com', 'mms' => '@myboostmobile.com'], 'cricket' => ['sms' => '@sms.cricketwireless.net', 'mms' => '@mms.cricketwireless.net'], 'uscellular' => ['sms' => '@email.uscc.net', 'mms' => '@mms.uscc.net'], 'googlefi' => ['sms' => '@msg.fi.google.com', 'mms' => '@msg.fi.google.com'], 'virgin' => ['sms' => '@vmobl.com', 'mms' => '@vmpix.com'], 'metro' => ['sms' => '@mymetropcs.com', 'mms' => '@mymetropcs.com'], ]; public function send() { $data = $this->payloadData(); if (empty($data)) { return $this->respondError('Invalid request data', Response::HTTP_BAD_REQUEST); } $rules = [ 'phone' => 'required|regex_match[/^\\d{10}$/]', 'message' => 'required|max_length[160]', 'carrier' => 'required|in_list[att,verizon,tmobile,sprint,boost,cricket,uscellular,googlefi,virgin,metro]', ]; $errors = $this->validateRequest($data, $rules); if (!empty($errors)) { return $this->respondValidationError($errors); } $phone = preg_replace('/[^0-9]/', '', $data['phone']); $message = $data['message']; $carrier = strtolower($data['carrier']); $type = $data['type'] ?? 'sms'; if (!isset($this->carrierGateways[$carrier])) { return $this->respondError('Invalid carrier', Response::HTTP_BAD_REQUEST); } $gateway = $this->carrierGateways[$carrier][$type] ?? $this->carrierGateways[$carrier]['sms']; $recipient = $phone . $gateway; try { /** @var EmailService $mailer */ $mailer = app(EmailService::class); $mailer->setTo($recipient); $mailer->setFrom(env('MAIL_FROM_ADDRESS', 'no-reply@alrahmaisgl.org'), env('MAIL_FROM_NAME', 'Alrahma Team')); $mailer->setSubject(''); $mailer->setMessage($message); if (!$mailer->send()) { return $this->respondError('Failed to send SMS', Response::HTTP_INTERNAL_SERVER_ERROR); } return $this->success([ 'phone' => $phone, 'carrier' => $carrier, 'type' => $type, 'sent' => true, ], 'SMS sent successfully'); } catch (\Throwable $e) { log_message('error', 'SMS send error: ' . $e->getMessage()); return $this->respondError('Failed to send SMS', Response::HTTP_INTERNAL_SERVER_ERROR); } } public function carriers() { $carriers = []; foreach ($this->carrierGateways as $key => $gateways) { $carriers[] = [ 'id' => $key, 'name' => ucfirst(str_replace(['us', 'google'], ['US ', 'Google '], $key)), 'sms_gateway' => $gateways['sms'], 'mms_gateway' => $gateways['mms'], ]; } return $this->success($carriers, 'Carriers retrieved successfully'); } }