0

I have a html bootstrap form and have a php code that sends a email of form information. This has a google reCaptcha check before the email is sent.

I copied the code that does the validation of the text, the email sending and the recaptcha from another php form that works.

How can I make the php code send the 2 images it receives from the form bootstrap form as attachments in the email.

These are my file upload form elements

<form role="form" class="form" action='https://opeturmo.com/parapente_ecuador/competencia_form.php' method='post'>
  <div class="form-group row">
    <div class="col-12"><label for="photo">Adjunte su foto - Add a photo of you</label></div>
    <div class="col-12"><p>IMPORTANTE: Adjunta una foto de tu cara. No de tu parapente o alguna otra cosa. Máx 10MB Tamaño: mayor de 400*400 px –IMPORTANT: A photo of your face. Not your glider or anything else. Max 10MB Size: not less than 400*400 px</p></div>
    <div class="col-12"><input type="file" class="form-control-file" id="photo" accept="image/*" name="my_file"></div>
  </div>
  <div class="form-group">
    <label for="pago">Adjunte su foto de pago - Add your payment photo</label>
    <p>IMPORTANTE: Adjunta una foto de tu cara. No de tu parapente o alguna otra cosa. Máx 10MB Tamaño: mayor de 400*400 px –IMPORTANT: A photo of your face. Not your glider or anything else. Max 10MB Size: not less than 400*400 px</p>
    <input type="file" class="form-control-file" id="pago" >
  </div>

and this is my php

<?php
//Checking For reCAPTCHA
$captcha;
if (isset($_POST['g-recaptcha-response'])) {
    $captcha = $_POST['g-recaptcha-response'];
}
// Checking For correct reCAPTCHA
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LcPkZEUAAAAAL4DJYl-y3iOl1TdavmqhsghRXeU&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
if (!$captcha || $response.success == false) {
    header('location: ' . $_SERVER['HTTP_REFERER']);
} else {
/* Check all form inputs using check_input function */
function check_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

 if( isset($_POST) ){     
    //user sumbission data
    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $date_sent = date('d/m/Y');
    $time = date('H:i:s');

    //form data
    $email = check_input($_POST['email']);
    //photo
    $file_name = $_FILES['my_file']['photo'];

    $participant_number = check_input($_POST['participant_number']);    
    $firstName = check_input($_POST['firstName']);
    $lastName = check_input($_POST['lastName']);
    $country = check_input($_POST['country']);
    $sexo = check_input($_POST['sexo']);
    $date = check_input($_POST['date']);
    $direccion = check_input($_POST['direccion']);
    $tel = check_input($_POST['tel']);
    $equipo = check_input($_POST['equipo']);
    $homologacion = check_input($_POST['homologacion']);
    $sponsor = check_input($_POST['sponsor']);
    $licenciaFAI = check_input($_POST['licenciaFAI']);
    $civilId = check_input($_POST['civilId']);
    $team = check_input($_POST['team']);
    $camisa = check_input($_POST['camisa']);
    $seguro = check_input($_POST['seguro']);
    $seguronumber = check_input($_POST['seguronumber']);
    $emergencyContact = check_input($_POST['emergencyContact']);
    $emergencyNumber = check_input($_POST['emergencyNumber']);
    $sangre = check_input($_POST['sangre']);

    //pago foto
    $file_pago = $_FILES['file_pago']['pago'];



    //send email if all is ok
    $headers = "From: opeturmo@opeturmo.com" . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    $emailbody = "<h2>Booking - Reservas</h2>
                  <p><strong>Email: </strong> {$email} </p>
                  <p><strong>Nuero participante: </strong> {$participant_number} </p>
                  <p><strong>Nombre: </strong> {$firstName} </p>
                  <p><strong>Apellido: </strong> {$lastName} </p>
                  <p><strong>Pais: </strong> {$country} </p>
                  <p><strong>Sexo: </strong> {$sexo} </p>
                  <p><strong>Fecha: </strong> {$date} </p>
                  <p><strong>Direccion: </strong> {$direccion} </p>
                  <p><strong>Telefono: </strong> {$tel} </p>
                  <p><strong>Marca equipo parapente: </strong> {$equipo} </p>
                  <p><strong>Sponsor: </strong> {$sponsor} </p>
                  <p><strong>Licencia Fai: </strong> {$licenciaFAI} </p>
                  <p><strong>Civil Id: </strong> {$civilId} </p>
                  <p><strong>Equipo con quien compute: </strong> {$team} </p>
                  <p><strong>Talla camisa: </strong> {$camisa} </p>
                  <p><strong>Compania Seguros: </strong> {$seguro} </p>
                  <p><strong>Poliza numero : </strong> {$seguronumber} </p>
                  <p><strong>Contacto de Emergencia : </strong> {$emergencyContact} </p>
                  <p><strong>Numero de Contacto de Emergencia : </strong> {$emergencyNumber} </p>
                  <p><strong>Tipo de Sangre : </strong> {$sangre} </p>

                  <p>This message was sent from the IP Address: {$ipaddress} on {$date_sent} at {$time}</p>";
    $body = "--$boundary\r\n";
        $body .="Content-Type: $file_type; name=".$file_name."\r\n";
        $body .="Content-Disposition: attachment; filename=".$file_name."\r\n";
        $body .="Content-Transfer-Encoding: base64\r\n";
        $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
        $body .= $encoded_content;

               mail ("opeturmo@gmail.com","Formulario Competencia",$emailbody,$body, $headers);
               //redirect back to form
    header('location: ' . $_SERVER['HTTP_REFERER']);

        }   







}
?>

I haven't done much with php so I am lost with this.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
NaNodine
  • 263
  • 1
  • 3
  • 12

0 Answers0