Automatic response php form

0

I have a basic form and I need to know how to configure an automatic response that attaches the corresponding file to "option 1" or "option 2". Can someone help me. Thanks

                <form action="envio.php" name="envio.php" method="post" enctype="multipart/form-data" class="form-inline">
                    <input type="text" class="form-control" name="nombre" id="nombre" placeholder="Nombre">
                    <input type="email" class="form-control" name="email" id="email" placeholder="Email">
                    <select name="opciones" class="form-control">
                        <option value="1">1</option>
                        <option value="2">2</option>
                    </select>
                    <input type="submit" class="btn btn-success" value="Enviar">
                </form>

This is the modified form

    
asked by Miguel 12.11.2017 в 11:52
source

1 answer

0

I would do it with the class PHPMailer , which you can download from here PHPMailer Github

The code I should use would be something similar to this

<?php

    require_once("includes/constantes.php");

            error_reporting(E_STRICT);
            date_default_timezone_set('Europe/Madrid');
            require_once('includes/class.phpmailer.php');
            //include("class.smtp.php");                                    // optional, gets called from within class.phpmailer.php if not 
                                                                            // already loaded
            $mail             = new PHPMailer();
            $mail->IsSMTP();                                                // telling the class to use SMTP
            $mail->Host       = $SERVIDOR_SMTP;                             // SMTP server
            $mail->SMTPDebug  = 1;                                          // enables SMTP debug information (for testing)
                                                                            // 1 = errors and messages
                                                                            // 2 = messages only
            $mail->SMTPAuth   = true;                                       // enable SMTP authentication
            $mail->Host       = $SERVIDOR_SMTP;                             // sets the SMTP server
            $mail->Port       = 25;                                         // set the SMTP port for the GMAIL server
            $mail->Username   = $correo_Usuario;                            // SMTP account username
            $mail->Password   = $correo_Clave;                              // SMTP account password
            $mail->SetFrom( $correo_copia, $correo_NombreCliente);
            $mail->AddReplyTo($correo, $correo_NombreCliente);
            $mail->AddCC($correo_copia,"");
            $mail->AddCC($correo1,"");
            if ($achivo !="none") {
                 $mail->AddAttachment($archivo,$archivo_name);
            }

            if (isset($dirtemp)){
                 $mail->AddAttachment($dirtemp,"Parte del Siniestro");
            }
            //$mail->AddBCC($correo_administrativo, $correo_NombreAdministrativo);
            $mail->Subject    = strtoupper($asunto);
            $mail->MsgHTML($body);
            $address = $correo_destino_usado;

            //echo "direccion:".$address;

            $mail->AddAddress($address);


?>

Where you must define your server variables, emails, passwords and other variables.

The part you care about would be the code

if ($achivo !="none") {
    $mail->AddAttachment($archivo,$archivo_name);
      }

Where $archivo will be the path of the attachment and $archivo_name would be the name of the file that will appear in the email

    
answered by 12.11.2017 в 12:40