Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'phpMailer/PHPMailerAutoload.php';
- require 'connection.php';
- $name = $_POST['name'];
- $email = $_POST['email'];
- $group = $_POST['group'];
- $exists = false;
- // Agregarlo a la Base de Datos
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- echo "Error";
- exit;
- }
- // Checar que no este registrado
- $query = mysqli_query($conn, "SELECT * FROM asistentes WHERE Correo='".$email."'");
- if(mysqli_num_rows($query) > 0){
- $exists = true;
- }
- if(!$exists) {
- $sql = "INSERT INTO asistentes (Nombre, Correo, Semestre)
- VALUES ('$name', '$email', '$group')";
- if ($conn->query($sql) === FALSE) {
- echo "Error";
- exit;
- }
- $conn->close();
- $mail = new PHPMailer;
- //$mail->SMTPDebug = 3; // Enable verbose debug output
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'xxx'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'xxx'; // SMTP username
- $mail->Password = 'xxx'; // SMTP password
- $mail->SMTPSecure = 'tsl'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = 25; // TCP port to connect to
- $mail->From = 'xxx';
- $mail->FromName = 'Taller de Desarrollo de Aplicaciones Web';
- $mail->addAddress($email, $name); // Add a recipient
- //$mail->addAddress('ellen@example.com'); // Name is optional
- //$mail->addReplyTo('info@example.com', 'Information');
- $mail->addBCC('xxx'); // Copia Invisible para Liz
- $mail->addBCC('xxx'); // Copia Invisible para mi
- //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
- //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = 'Bienvenido/a al Taller Desarrollo de Aplicaciones Web ';
- $myBody = file_get_contents('email.html');
- $exploded = explode(" ", $name);
- $firstName = $exploded[0];
- $myBody = str_replace("{labelNombre}", $firstName, $myBody);
- $mail->Body = $myBody;
- //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
- if(!$mail->send()) {
- echo 'Error.';
- exit;
- }
- echo 'Success';
- } else {
- echo "Duplication";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement