SMS API integrated with PHP

Asked

Viewed 1,165 times

0

I have a form of scheduling visits, when the user makes his scheduling and confirms is triggered an email to the same one with scheduling information. I wonder if anyone has ever integrated an SMS API with PHP.

Example:

My Send API uses the following URL to send the SMS

http://sitedeenvio.com.br/api/v1/send?cpf=XXXXXXXXXXX&password=XXXXXXXXXX&type=short&numbers=55DDDCELULAR&messages=Hello World

How do I include this API as soon as it triggers the already confirmation email to the user about scheduling.

Data input form code part

            <div id="wizard-frame-3" class="wizard-frame" style="display:none;">
                <div class="frame-container">

                    <h3 class="frame-title"><?php echo $this->lang->line('step_three_title'); ?></h3>

                    <div class="frame-content row">
                        <div class="col-xs-12 col-sm-6">
                            <div class="form-group">
                                <label for="first-name" class="control-label"><?php echo $this->lang->line('first_name'); ?> *</label>
                                <input type="text" id="first-name" class="required form-control" maxlength="100" />
                            </div>
                            <div class="form-group">
                                <label for="last-name" class="control-label"><?php echo $this->lang->line('last_name'); ?> *</label>
                                <input type="text" id="last-name" class="required form-control" maxlength="250" />
                            </div>
                            <div class="form-group">
                                <label for="email" class="control-label"><?php echo $this->lang->line('email'); ?> *</label>
                                <input type="text" id="email" class="required form-control" maxlength="250" />
                            </div>
                            <div class="form-group">
                                <label for="phone-number" class="control-label"><?php echo $this->lang->line('phone_number'); ?> *</label>
                                <input type="text" id="phone-number" class="required form-control" maxlength="60" />
                            </div>
                        </div>

                        <div class="col-xs-12 col-sm-6">
                            <div class="form-group">
                                <label for="address" class="control-label"><?php echo $this->lang->line('address'); ?></label>
                                <input type="text" id="address" class="form-control" maxlength="250" />
                            </div>
                            <div class="form-group">
                                <label for="city" class="control-label"><?php echo $this->lang->line('city'); ?></label>
                                <input type="text" id="city" class="form-control" maxlength="120" />
                            </div>
                            <div class="form-group">
                                <label for="zip-code" class="control-label"><?php echo $this->lang->line('zip_code'); ?></label>
                                <input type="text" id="zip-code" class="form-control" maxlength="120" />
                            </div>
                            <div class="form-group">
                                <label for="notes" class="control-label"><?php echo $this->lang->line('notes'); ?></label>
                                <textarea id="notes" maxlength="500" class="form-control" rows="3"></textarea>
                            </div>
                        </div>

                        <em id="form-message" class="text-danger"><?php echo $this->lang->line('fields_are_required'); ?></em>
                    </div>
                </div>

                <div class="command-buttons">
                    <button type="button" id="button-back-3" class="btn button-back btn-default"
                            data-step_index="3"><span class="glyphicon glyphicon-backward"></span>
                        <?php echo $this->lang->line('back'); ?>
                    </button>
                    <button type="button" id="button-next-3" class="btn button-next btn-primary"
                            data-step_index="3">
                        <?php echo $this->lang->line('next'); ?>
                        <span class="glyphicon glyphicon-forward"></span>
                    </button>
                </div>

            </div>

            <?php
                // ------------------------------------------------------
                // APPOINTMENT DATA CONFIRMATION
                // ------------------------------------------------------ ?>

            <div id="wizard-frame-4" class="wizard-frame" style="display:none;">
                <div class="frame-container">
                    <h3 class="frame-title"><?php echo $this->lang->line('step_four_title'); ?></h3>
                    <div class="frame-content row">
                        <div id="appointment-details" class="col-xs-12 col-sm-6"></div>
                        <div id="customer-details" class="col-xs-12 col-sm-6"></div>
                    </div>
                    <?php if ($this->settings_model->get_setting('require_captcha') === '1'): ?>
                    <div class="frame-content row">
                        <div class="col-sm-12 col-md-6">
                            <h4 class="captcha-title">
                                CAPTCHA
                                <small class="glyphicon glyphicon-refresh"></small>
                            </h4>
                            <img class="captcha-image" src="<?php echo site_url('captcha'); ?>">
                            <input class="captcha-text" type="text" value="" />
                            <span id="captcha-hint" class="help-block" style="opacity:0">&nbsp;</span>
                        </div>
                    </div>
                    <?php endif; ?>
                </div>

                <div class="command-buttons">
                    <button type="button" id="button-back-4" class="btn button-back btn-default"
                            data-step_index="4">
                        <span class="glyphicon glyphicon-backward"></span>
                        <?php echo $this->lang->line('back'); ?>
                    </button>
                    <form id="book-appointment-form" style="display:inline-block" method="post">
                        <button id="book-appointment-submit" type="button" class="btn btn-success">
                            <span class="glyphicon glyphicon-ok"></span>
                            <?php
                                echo (!$manage_mode) ? $this->lang->line('confirm')
                                        : $this->lang->line('update');
                            ?>
                        </button>
                        <input type="hidden" name="csrfToken" />
                        <input type="hidden" name="post_data" />
                    </form>


                </div>

            </div>

File sending the email

<title>Appointment Details</title>



    <div id="content" style="padding: 10px 15px;">
        <h2>$email_title</h2>
        <p>$email_message</p>

        <h2>Appointment Details</h2>
        <table id="appointment-details">
            <tr>
                <td class="label" style="padding: 3px;font-weight: bold;">Service</td>
                <td style="padding: 3px;">$appointment_service</td>
            </tr>
            <tr>
                <td class="label" style="padding: 3px;font-weight: bold;">Provider</td>
                <td style="padding: 3px;">$appointment_provider</td>
            </tr>
            <tr>
                <td class="label" style="padding: 3px;font-weight: bold;">Start</td>
                <td style="padding: 3px;">$appointment_start_date</td>
            </tr>
            <tr>
                <td class="label" style="padding: 3px;font-weight: bold;">End</td>
                <td style="padding: 3px;">$appointment_end_date</td>
            </tr>
        </table>

        <h2>Customer Details</h2>
        <table id="customer-details">
            <tr>
                <td class="label" style="padding: 3px;font-weight: bold;">Name</td>
                <td style="padding: 3px;">$customer_name</td>
            </tr>
            <tr>
                <td class="label" style="padding: 3px;font-weight: bold;">Email</td>
                <td style="padding: 3px;">$customer_email</td>
            </tr>
            <tr>
                <td class="label" style="padding: 3px;font-weight: bold;">Phone</td>
                <td style="padding: 3px;">$customer_phone</td>
            </tr>
            <tr>
                <td class="label" style="padding: 3px;font-weight: bold;">Address</td>
                <td style="padding: 3px;">$customer_address</td>
            </tr>
        </table>

        <h2>Appointment Link</h2>
        <a href="$appointment_link" style="width: 600px;">$appointment_link</a>
    </div>


</div>

  • Alex I have an integrated text system with email, I was only doubtful you want to send the text after sending the email?

  • Diego, I have a scheduling form that already works, as soon as the user performs a scheduling automatically already triggers to his email the scheduling information that he did OK? Dai I have an SMS sending system that has an API that can be integrated into this system of scheduling visits. wanted to make sure that as soon as he confirmed the appointment and sent the confirmation email he would send a text to the number of the person who was already registered in the form. managed to understand?

  • OK I’ll post the answer.

  • Diego if you want, put part of my code here.

  • place, which I try to adapt.

  • I updated the code on the question already, if you need anything else I pick up here..

  • vc send the email with Function mail(); correct?

  • That’s right, with mail();

Show 3 more comments

1 answer

0


I adapted a code I have here, to try to help you ##

u informed that your form and sending email is already working. so I will not pay attention to this:

//SEU CODIGO DE AGENDAMENTO.
//supondo que vc envia o sms depois da resposta do e-mail
$email = "[email protected]";
$assunto = "Assunto do e-mail";
$corpo = "Aqui escreve o teu contéudo.";
$cabecalho = "From: [email protected]" . "\r\n" .
        "Reply-To:" . $email . "\r\n" .
        "X-mailer: PHP/" . phpversion();

$assunto = '=?UTF-8?B?' . base64_encode($assunto) . '?=';

if (mail($email, $assunto, $corpo, $cabecalho)) { //se o email for enviado da TRUE e passa pelo if
 $msg = trim($corpo);// supondo ser a msm mensagem
    $url = "http://sitedeenvio.com.br/api/v1/send?cpf=XXXXXXXXXXX&password=XXXXXXXXXX&type=short&numbers=55DDDCELULAR&messages=$msg";
    $link = curl_init();
    curl_setopt($link, CURLOPT_HEADER, 0);
    curl_setopt($link, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($link, CURLOPT_URL, $url);
    $resposta = curl_exec($link); // resposta da sua plataforma de envio de sms
    var_dump($resposta); //resposta do envio do sms.
} else {
    echo 'não enviado!';
}

PHP mail reference

  • Cool, I will include in my code and make the necessary changes but already clarified me a lot. Thank you very much..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.