It seems like you're encountering an issue where your code works in a local environment but not in production. This could be due to a variety of reasons, such as differences in environment configuration, network issues, or permissions. Here are some steps you can take to troubleshoot and resolve the issue:
-
Check Environment Variables: Ensure that the environment variables like
SEND_WHATSAPP_URL,CHANNEL_ID, andAPI_KEYare correctly set in your production environment. -
SSL Verification: If your production server is enforcing SSL verification and you're trying to hit an HTTPS endpoint, you might need to add an option to your cURL request to handle SSL.
-
Error Handling: Improve error handling in your cURL request to get more insight into what might be going wrong.
-
Server Logs: Check your server logs for any errors that might be occurring on the production server.
-
Firewall or Network Issues: Ensure that your production server is not behind a firewall or network configuration that is preventing it from making outbound HTTP requests.
Here's an updated version of your function with improved error handling:
public static function SendSignatureReminderWhatsapp(array $info)
{
$phone = PhoneHelper::formatPhoneNumber($info['phone']);
$ch = curl_init();
$url = env('SEND_WHATSAPP_URL');
$data = [
// ... your data array
];
$data_string = json_encode($data);
$headers = [
"Authorization: AccessKey " . env('API_KEY'),
"Content-Type: application/json"
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Add this line if you have SSL verification issues
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
// If cURL error exists, log it
Log::error('cURL Error: ' . curl_error($ch));
}
curl_close($ch);
Log::info('Response: ' . $response);
Log::info('HTTP Code: ' . $httpCode);
}
Make sure to replace env('API_KEY') with the actual API key for your production environment. If you're disabling SSL verification (CURLOPT_SSL_VERIFYPEER), be aware that this is not recommended for production environments as it can pose security risks.
If after these changes you're still facing issues, you might want to reach out to MessageBird support with the details of the error you're encountering, as it could be related to their service or your account configuration on their end.