This project allows you to send SMS messages via a serial port using a C# application. The program takes a COM port, a recipient's phone number, and sends a predefined SMS message to the recipient.
- Sends SMS using a GSM modem connected via a serial port.
- Configurable port and recipient's phone number.
- Easy integration with PHP backend to send SMS from a web application.
- .NET Framework 4.8 (or higher).
- A GSM modem or mobile phone connected to the computer via a serial port.
- PHP running on your server.
- Composer for managing PHP dependencies (if necessary).
-
Open the
SendSMSApp
project in Visual Studio. -
Compile the project to generate the executable file (
SendSMSApp.exe
). -
Ensure the C# application can be run using a command like:
SendSMSApp.exe COM8 your_mobile_number_here
To integrate the C# application with a PHP application, you can call the executable using PHP's shell_exec()
function.
Here’s an example PHP script to run the C# executable and send an SMS:
<?php
$port = 'COM6'; // Example port, replace with actual port
$guardianNumber = '09911234567'; // Replace with actual phone number
// Path to your compiled C# executable
$exePath = realpath('lib/SendSMSApp.exe'); // Ensure the path is correct
// Build the command to execute the C# program with parameters
$command = escapeshellcmd("{$exePath} {$port} {$guardianNumber}");
// Execute the C# executable
$output = shell_exec($command);
// Check if the execution was successful and display the result
if ($output) {
echo "Message sent successfully!";
} else {
echo "Failed to send the message.";
}
?>
Ensure the SendSMSApp.exe
is compiled and placed in the correct directory.
Update the PHP script with the correct path to the .exe
file.
When the sendSMS.php
file is triggered (via web browser or API), it will send an SMS to the specified phone number.
Place the compiled .exe
file (e.g., SendSMSApp.exe
) in your project directory or a known location.
When you compile the C# file. copy everything it generated like the screenshot below. Place these files inside your project or have a folder named "lib/SendSMSAPI" and put the files there.
Ensure that the PHP script (sendSMS.php
) is set up to call the .exe
file.
Execute the PHP script via your browser or API endpoint.
The recipient will receive the SMS message, and the system will print the result on the browser.
- Port Issues: Make sure the serial port is correctly configured and accessible.
- GSM Modem: Ensure that the GSM modem is powered on and connected to the correct port.
- Permissions: Ensure that the server running PHP has permission to execute the C# executable.