Advertisement
mastersuv

Mailing

Apr 19th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.46 KB | None | 0 0
  1. <?php
  2. require 'phpMailer/PHPMailerAutoload.php';
  3. require 'connection.php';
  4.  
  5. $name = $_POST['name'];
  6. $email = $_POST['email'];
  7. $group = $_POST['group'];
  8. $exists = false;
  9.  
  10. // Agregarlo a la Base de Datos
  11. // Create connection
  12. $conn = new mysqli($servername, $username, $password, $dbname);
  13. // Check connection
  14. if ($conn->connect_error) {
  15.     echo "Error";
  16.     exit;
  17. }
  18.  
  19. // Checar que no este registrado
  20. $query = mysqli_query($conn, "SELECT * FROM asistentes WHERE Correo='".$email."'");
  21.  
  22. if(mysqli_num_rows($query) > 0){
  23.     $exists = true;
  24. }
  25.  
  26. if(!$exists) {
  27.     $sql = "INSERT INTO asistentes (Nombre, Correo, Semestre)
  28.     VALUES ('$name', '$email', '$group')";
  29.  
  30.     if ($conn->query($sql) === FALSE) {
  31.         echo "Error";
  32.         exit;
  33.     }
  34.  
  35.     $conn->close();
  36.  
  37.     $mail = new PHPMailer;
  38.     //$mail->SMTPDebug = 3;                               // Enable verbose debug output
  39.  
  40.     $mail->isSMTP();                                      // Set mailer to use SMTP
  41.     $mail->Host = 'xxx';                // Specify main and backup SMTP servers
  42.     $mail->SMTPAuth = true;                               // Enable SMTP authentication
  43.     $mail->Username = 'xxx';                 // SMTP username
  44.     $mail->Password = 'xxx';                           // SMTP password
  45.     $mail->SMTPSecure = 'tsl';                            // Enable TLS encryption, `ssl` also accepted
  46.     $mail->Port = 25;                                    // TCP port to connect to
  47.  
  48.     $mail->From = 'xxx';
  49.     $mail->FromName = 'Taller de Desarrollo de Aplicaciones Web';
  50.     $mail->addAddress($email, $name);     // Add a recipient
  51.     //$mail->addAddress('ellen@example.com');               // Name is optional
  52.     //$mail->addReplyTo('info@example.com', 'Information');
  53.     $mail->addBCC('xxx');           // Copia Invisible para Liz
  54.     $mail->addBCC('xxx');       // Copia Invisible para mi
  55.  
  56.     //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
  57.     //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
  58.     $mail->isHTML(true);                                  // Set email format to HTML
  59.  
  60.     $mail->Subject = 'Bienvenido/a al Taller Desarrollo de Aplicaciones Web ';
  61.     $myBody = file_get_contents('email.html');
  62.     $exploded = explode(" ", $name);
  63.     $firstName = $exploded[0];
  64.     $myBody = str_replace("{labelNombre}", $firstName, $myBody);
  65.     $mail->Body = $myBody;
  66.     //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  67.  
  68.     if(!$mail->send()) {
  69.         echo 'Error.';
  70.         exit;
  71.     }
  72.     echo 'Success';
  73. } else {
  74.     echo "Duplication";
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement