-1

I tried to solved by myself reading how php form works and I haven't arrived to an optimal solution. I still do not recive the mail with the user information.

// My php file named: sendbymail.php

<?php
//Importar variables

@$name = addslashes($_POST['name']);
@$ci = addslashes($_POST['ci']);
@$phone = addslashes($_POST['phone']);
@$Atype = addslashes($_POST['Atype']);
@$dept = addslashes($_POST['dept']);
@$municipality = addslashes($_POST['municipality']);
@$zone = addslashes($_POST['zone']);
@$uv = addslashes($_POST['uv']);
@$mza = addslashes($_POST['mza']);
@$lote = addslashes($_POST['lote']);
@$urb = addslashes($_POST['urb']);
@$street = addslashes($_POST['street']);
@$bank = addslashes($_POST['bank']);
@$branch = addslashes($_POST['branch']);
@$officer = addslashes($_POST['officer']);
@$oemail = addslashes($_POST['oemail']);

$to ="my@email.com";
$subject="Contacto desde el Sitio Web";
$message = "$name ha enviado un mensaje desde la web www.mywebsite.com\n"
. "\n"
. "Nombre: $name\n"
. "Apellido: $ci\n"
. "Empresa: $phone\n"
. "Email: $Atype\n"
. "Departamento: $dept\n"
. "Mensaje: $municipality\n"
. "Mensaje: $zone\n"
. "Mensaje: $uv\n"
. "Mensaje: $mza\n"
. "Mensaje: $lote\n"
. "Mensaje: $urb\n"
. "Mensaje: $street\n"
. "Mensaje: $bank\n"
. "Mensaje: $branch\n"
. "Mensaje: $officer\n"
. "Mensaje: $oemail\n"
. "\n";
$headers = "From $oemail\n"
. "Reply-To: $oemail\n";
$headers = "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers = "MIME-Version: 1.0" . "\r\n";

mail($to, $subject, $message, $headers);
?>

// The html form. I used the post method, from index.html

 <form action="sendbyemail.php" method="post" id="reused_form">

                <!-- Soliciante -->
                <fieldset>
                    <legend>Datos del solicitante</legend>
                 
                    <!-- Persona Natural -->
                    <div id="natural1">
                        <label for="name">Nombre(s) y Apellido(s) / Razon Social:</label>
                        <input type="text" id="name" name="name" required>
                        <br>
                        <label for="ci">C.I. / N.I.T.:</label>
                        <input type="text" id="ci" inputmode="numeric" name="ci" required>
                        <br>
                        <label for="phone">Teléfono de contacto</label>
                        <input type="text" id="phone" inputmode="numeric" name="phone" required>
                    </div>
                </fieldset>
        
                <!-- T. Valuacion -->
                <fieldset>
        
                    <legend>Valuacion requerida</legend>
        
                    <label for="Atype">Tipo de Avaluo:</label>
                    <select id="Atype" name="Atype">
                        <option value="empty"></option>
                        <option value="Departamento">P. Horizontal</option>
                        <option value="Inmueble">Planta/Galpon Industrial</option>
                        <option value="Inmueble">Maquinaria industrial</option>
                        <option value="Inmueble">Vehiculos - Maq. Pesada</option>
                        <option value="Inmueble">P. rural</option>
                        <option value="Inmueble">Terreno</option>
                        <option value="Inmueble">Vivienda</option>
                        <option value="Inmueble">Obra civil</option>
                        <option value="Inmueble">Otros</option>
                    </select>
                </fieldset>


                <!-- Datos de Ubicacion -->
                <fieldset>
                    <legend>Ubicación del bien</legend>
                    
                    <!-- Departamento -->
                    <label for="dept">Departamento:</label>
                    <select id="dept" name="dept" required>
                        <option value="empty"></option>
                        <option value="beni">Beni</option>
                        <option value="chuquisaca">Chuquisaca</option>
                        <option value="cochabamba">Cochabamba</option>
                        <option value="laPaz">La Paz</option>
                        <option value="oruro">Oruro</option>
                        <option value="pando">Pando</option>
                        <option value="potosi">Potosí</option>
                        <option value="santaCruz">Santa Cruz</option>
                        <option value="tarija">Tarija</option>
                    </select>
                    
                    <!-- Municipio -->
                    <!-- This must be a select option and the options should only appear to the corresponding departament -->
                    <label for="municipality">Municipio:</label>
                    <input type="text" id="municipality" name="municipality" required>
        
                    <!-- Zona -->
                    <label for="zone">Zona:</label>
                    <input type="text" id="zone" name="zone" required>
        
                    <!-- Unidad Vecinal -->
                    <label for="uv">U.V.:</label>
                    <input type="text" id="uv" name="uv" required>
        
                    <!-- Manzano -->
                    <label for="mza">Manazana:</label>
                    <input type="text" id="mza" name="mza" required>
        
                    <!-- Lote -->
                    <label for="lote">Lote:</label>
                    <input type="text" id="lote" name="lote" required>
        
                    <!-- Urbanizacion -->
                    <label for="urb">Urbanización:</label>
                    <input type="text" id="urb" name="urb" required>
        
                    <!-- Avenida o Calle -->
                    <label for="street">Avenida o Calle, Nro:</label>
                    <input type="text" id="street" name="street" required>
        
                </fieldset>
        
                <!-- Entidad Financiera -->
                <fieldset>
                    <legend>Entidad Financiera</legend>
                    
                    <!-- Entidad -->
                    <label for="bank">Entidad:</label>
                    <select id="bank"name="bank">
                        <option value="empty"></option>
                        <option value="bdr">Banco de Desarrollo Productivo S.A.M</option>
                        <option value="bcr">Banco de Crédito de Bolivia S.A.</option>
                        <option value="bec">Banco Económico S.A.</option>
                        <option value="bfs">Banco Fassil S.A</option>
                        <option value="bfo">Banco Fortaleza S.A.</option>
                        <option value="bpr">Banco Prodem S.A.</option>
                        <option value="bun">Banco Union S.A.</option>
                        <option value="pco">Banco Pyme de la Comunidad S.A.</option>
                        <option value="ici">CIDRE IFD</option>
                        <option value="icr">CRECER IFD</option>
                    </select>
        
                    <!-- Agencia -->
                    <label for="branch">Agencia o Sucursal:</label>
                    <input type="text" id="branch" name="branch">
        
                    <!-- Oficial de Credito -->
                    <label for="officer">Oficial de Crédito:</label>
                    <input type="text" id="officer" name="officer">
        
                    <!-- Correo Electrónico (del oficial de credito) -->
                    <label for="oemail">Correo Electrónico:</label>
                    <input type="email" id="oemail" name="oemail">

                    <!-- Copia de correo al usario -->
                    <input type="checkbox" name="emailcopy" id="emailcopy" class="sr-only">
                    <label for="emailcopy" class="sr-only">Deseo recibir una copia de la solicitud</label>      
        
                </fieldset>

                <div id="tocs">
                    <input type="checkbox" name-="tocs" id="tocs" required>
                    <label for="tocs">He leido y acepto la <a href="tocs.html" class="lnk">Política de Privacidad</a> y los <a href="tocs.html" class="lnk"> <i>Términos y Condiciones</i></a> de uso</label>
                </div>

                <!-- Captcha / enviar / reset -->
                <div class="flex-layout01">
                    <div class="sr-only">Captcha</div>     
                    <input type="submit" value="Enviar" class="btn btn-1 buzz-out-on-hover">
                    <button type="reset" class="btn btn-2 buzz-out-on-hover">Reset</button>
                </div>
        
                </form>

I tried to solved by myself reading how php form works and I haven't arrived to an optimal solution. I still do not recive the mail with the user information.

aynber
  • 22,380
  • 8
  • 50
  • 63
tiamat
  • 3
  • 1
  • What **exactly** is not working? What have you tried to resolve the problem? – Nico Haase Dec 06 '22 at 16:36
  • 1
    Also, stop using `@` in your PHP code. That hides an error - but this also means you won't be notified about an error ;) – Nico Haase Dec 06 '22 at 16:37
  • Never use `addslashes`. Always use an escaping function specific to the data format you are escaping for (unless there's something better than escaping, like using parametrised queries for SQL). HTML doesn't even use slashes for escaping!! – Quentin Dec 06 '22 at 16:38
  • Thank you so much @NicoHaase. To answer your first question, I do not receive the form information in my email. Where is $to I put my email and I never get the information. Also my collegues told me that when they submit the form the 404 error protocol appears. – tiamat Dec 06 '22 at 18:02

1 Answers1

-2
  1. Make sure that the form is properly configured to send data to the PHP script.

  2. Validate the data sent by the form and make sure all the required fields are present.

  3. Use the $_POST array to access the data sent by the form.

  4. Use the filter_var() function to validate the data.

  5. Use the mail() function to send the message.

  6. Use error handling to check for any errors in the form submission.

  7. Use the stripslashes() function to remove any unwanted characters from the message.

  8. Use the htmlspecialchars() function to prevent any malicious code from being sent with the message.

  9. Use the wordwrap() function to format the message for better readability.

  10. Set the correct content type for the email using the header() function.