_mime_types() public static method

Get the MIME type for a file extension.
public static _mime_types ( string $ext = '' ) : string
$ext string File extension
return string MIME type of file.
 /**
  * Miscellaneous calls to improve test coverage and some small tests
  */
 public function testMiscellaneous()
 {
     $this->assertEquals('application/pdf', PHPMailer::_mime_types('pdf'), 'MIME TYPE lookup failed');
     $this->Mail->addCustomHeader('SomeHeader: Some Value');
     $this->Mail->clearCustomHeaders();
     $this->Mail->clearAttachments();
     $this->Mail->isHTML(false);
     $this->Mail->isSMTP();
     $this->Mail->isMail();
     $this->Mail->isSendmail();
     $this->Mail->isQmail();
     $this->Mail->setLanguage('fr');
     $this->Mail->Sender = '';
     $this->Mail->createHeader();
     $this->assertFalse($this->Mail->set('x', 'y'), 'Invalid property set succeeded');
     $this->assertTrue($this->Mail->set('Timeout', 11), 'Valid property set failed');
     //Test pathinfo
     $a = '/mnt/files/飛兒樂 團光茫.mp3';
     $q = PHPMailer::mb_pathinfo($a);
     $this->assertEquals($q['dirname'], '/mnt/files', 'UNIX dirname not matched');
     $this->assertEquals($q['basename'], '飛兒樂 團光茫.mp3', 'UNIX basename not matched');
     $this->assertEquals($q['extension'], 'mp3', 'UNIX extension not matched');
     $this->assertEquals($q['filename'], '飛兒樂 團光茫', 'UNIX filename not matched');
     $this->assertEquals(PHPMailer::mb_pathinfo($a, PATHINFO_DIRNAME), '/mnt/files', 'Dirname path element not matched');
     $this->assertEquals(PHPMailer::mb_pathinfo($a, 'filename'), '飛兒樂 團光茫', 'Filename path element not matched');
     $a = 'c:\\mnt\\files\\飛兒樂 團光茫.mp3';
     $q = PHPMailer::mb_pathinfo($a);
     $this->assertEquals($q['dirname'], 'c:\\mnt\\files', 'Windows dirname not matched');
     $this->assertEquals($q['basename'], '飛兒樂 團光茫.mp3', 'Windows basename not matched');
     $this->assertEquals($q['extension'], 'mp3', 'Windows extension not matched');
     $this->assertEquals($q['filename'], '飛兒樂 團光茫', 'Windows filename not matched');
 }
Example #2
0
 /**
  * Miscellaneous calls to improve test coverage and some small tests
  */
 function test_Miscellaneous()
 {
     $this->assertEquals('application/pdf', PHPMailer::_mime_types('pdf'), 'MIME TYPE lookup failed');
     $this->Mail->AddCustomHeader('SomeHeader: Some Value');
     $this->Mail->ClearCustomHeaders();
     $this->Mail->ClearAttachments();
     $this->Mail->IsHTML(false);
     $this->Mail->IsSMTP();
     $this->Mail->IsMail();
     $this->Mail->IsSendMail();
     $this->Mail->IsQmail();
     $this->Mail->SetLanguage('fr');
     $this->Mail->Sender = '';
     $this->Mail->CreateHeader();
     $this->assertFalse($this->Mail->set('x', 'y'), 'Invalid property set succeeded');
     $this->assertTrue($this->Mail->set('Timeout', 11), 'Valid property set failed');
     $this->Mail->getFile(__FILE__);
 }
Example #3
0
 /**
  * Miscellaneous calls to improve test coverage and some small tests.
  */
 public function testMiscellaneous()
 {
     $this->assertEquals('application/pdf', PHPMailer::_mime_types('pdf'), 'MIME TYPE lookup failed');
     $this->Mail->addCustomHeader('SomeHeader: Some Value');
     $this->Mail->clearCustomHeaders();
     $this->Mail->clearAttachments();
     $this->Mail->isHTML(false);
     $this->Mail->isSMTP();
     $this->Mail->isMail();
     $this->Mail->isSendmail();
     $this->Mail->isQmail();
     $this->Mail->setLanguage('fr');
     $this->Mail->Sender = '';
     $this->Mail->createHeader();
     $this->assertFalse($this->Mail->set('x', 'y'), 'Invalid property set succeeded');
     $this->assertTrue($this->Mail->set('Timeout', 11), 'Valid property set failed');
     $this->assertTrue($this->Mail->set('AllowEmpty', null), 'Null property set failed');
     $this->assertTrue($this->Mail->set('AllowEmpty', false), 'Valid property set of null property failed');
     //Test pathinfo
     $a = '/mnt/files/飛兒樂 團光茫.mp3';
     $q = PHPMailer::mb_pathinfo($a);
     $this->assertEquals($q['dirname'], '/mnt/files', 'UNIX dirname not matched');
     $this->assertEquals($q['basename'], '飛兒樂 團光茫.mp3', 'UNIX basename not matched');
     $this->assertEquals($q['extension'], 'mp3', 'UNIX extension not matched');
     $this->assertEquals($q['filename'], '飛兒樂 團光茫', 'UNIX filename not matched');
     $this->assertEquals(PHPMailer::mb_pathinfo($a, PATHINFO_DIRNAME), '/mnt/files', 'Dirname path element not matched');
     $this->assertEquals(PHPMailer::mb_pathinfo($a, PATHINFO_BASENAME), '飛兒樂 團光茫.mp3', 'Basename path element not matched');
     $this->assertEquals(PHPMailer::mb_pathinfo($a, 'filename'), '飛兒樂 團光茫', 'Filename path element not matched');
     $a = 'c:\\mnt\\files\\飛兒樂 團光茫.mp3';
     $q = PHPMailer::mb_pathinfo($a);
     $this->assertEquals($q['dirname'], 'c:\\mnt\\files', 'Windows dirname not matched');
     $this->assertEquals($q['basename'], '飛兒樂 團光茫.mp3', 'Windows basename not matched');
     $this->assertEquals($q['extension'], 'mp3', 'Windows extension not matched');
     $this->assertEquals($q['filename'], '飛兒樂 團光茫', 'Windows filename not matched');
     $this->assertEquals(PHPMailer::filenameToType('abc.jpg?xyz=1'), 'image/jpeg', 'Query string not ignored in filename');
     $this->assertEquals(PHPMailer::filenameToType('abc.xyzpdq'), 'application/octet-stream', 'Default MIME type not applied to unknown extension');
     //Line break normalization
     $eol = $this->Mail->LE;
     $b1 = "1\r2\r3\r";
     $b2 = "1\n2\n3\n";
     $b3 = "1\r\n2\r3\n";
     $this->Mail->LE = "\n";
     $t1 = "1{$this->Mail->LE}2{$this->Mail->LE}3{$this->Mail->LE}";
     $this->assertEquals($this->Mail->fixEOL($b1), $t1, 'Failed to normalize line breaks (1)');
     $this->assertEquals($this->Mail->fixEOL($b2), $t1, 'Failed to normalize line breaks (2)');
     $this->assertEquals($this->Mail->fixEOL($b3), $t1, 'Failed to normalize line breaks (3)');
     $this->Mail->LE = "\r\n";
     $t1 = "1{$this->Mail->LE}2{$this->Mail->LE}3{$this->Mail->LE}";
     $this->assertEquals($this->Mail->fixEOL($b1), $t1, 'Failed to normalize line breaks (4)');
     $this->assertEquals($this->Mail->fixEOL($b2), $t1, 'Failed to normalize line breaks (5)');
     $this->assertEquals($this->Mail->fixEOL($b3), $t1, 'Failed to normalize line breaks (6)');
     $this->Mail->LE = $eol;
 }
Example #4
0
 /**
  * @param $extension
  *
  * @return mixed
  */
 public function get_mime_type_from_file_extension($extension)
 {
     global $phpmailer;
     // (Re)create it, if it's gone missing
     if (!$phpmailer instanceof PHPMailer) {
         require_once ABSPATH . WPINC . '/class-phpmailer.php';
         require_once ABSPATH . WPINC . '/class-smtp.php';
         $phpmailer = new PHPMailer(true);
     }
     return $phpmailer->_mime_types($extension);
 }
Example #5
0
 protected function mail_mime_content_type($filename)
 {
     return PHPMailer::_mime_types(array_pop(explode('.', $filename)));
 }
Example #6
0
 /**
  *  Realiza el envio del email propiamente dicho
  */
 function enviar()
 {
     require_once '3ros/phpmailer/class.phpmailer.php';
     //Se obtiene la configuración del SMTP
     $this->datos_configuracion = $this->get_datos_configuracion_smtp();
     if (!isset($this->desde)) {
         $this->desde = $this->datos_configuracion['from'];
     }
     //Construye y envia el mail
     $mail = new PHPMailer();
     $mail->IsSMTP();
     if ($this->debug) {
         $mail->SMTPDebug = true;
     }
     $mail->Timeout = $this->timeout;
     $host = trim($this->datos_configuracion['host']);
     if (isset($this->datos_configuracion['seguridad']) && trim($this->datos_configuracion['seguridad']) != '') {
         if ($this->datos_configuracion['seguridad'] == 'ssl') {
             if (!extension_loaded('openssl')) {
                 throw new toba_error('Para usar un SMTP con encriptación SSL es necesario activar la extensión "openssl" en php.ini');
             }
         }
         $mail->set('SMTPSecure', $this->datos_configuracion['seguridad']);
     }
     if (isset($this->datos_configuracion['puerto']) && trim($this->datos_configuracion['puerto']) != '') {
         $mail->set('Port', $this->datos_configuracion['puerto']);
     }
     $mail->Host = trim($host);
     if (isset($this->datos_configuracion['auth']) && $this->datos_configuracion['auth']) {
         $mail->SMTPAuth = true;
         $mail->Username = trim($this->datos_configuracion['usuario']);
         $mail->Password = trim($this->datos_configuracion['clave']);
     }
     $mail->From = $this->desde;
     if (isset($this->datos_configuracion['nombre_from']) && trim($this->datos_configuracion['nombre_from']) != '') {
         $this->desde_nombre = $this->datos_configuracion['nombre_from'];
     }
     if (isset($this->desde_nombre)) {
         $mail->FromName = $this->desde_nombre;
     } else {
         $mail->FromName = $this->desde;
     }
     $mail->AddAddress($this->hacia);
     foreach ($this->cc as $copia) {
         $mail->AddCC($copia);
     }
     foreach ($this->bcc as $copia) {
         $mail->AddBCC($copia);
     }
     if (isset($this->reply_to)) {
         $mail->AddReplyTo($this->reply_to);
     }
     if (isset($this->confirmacion)) {
         $mail->ConfirmReadingTo = $this->confirmacion;
     }
     $mail->Subject = $this->asunto;
     $mail->Body = $this->cuerpo;
     $mail->IsHTML($this->html);
     $temporales = array();
     $dir_temp = toba::proyecto()->get_path_temp();
     foreach (array_keys($this->adjuntos) as $id_adjunto) {
         $archivo = tempnam($dir_temp, 'adjunto');
         file_put_contents($archivo, $this->adjuntos[$id_adjunto]['archivo']);
         $temporales[] = $archivo;
         $tipo = $mail->_mime_types($this->adjuntos[$id_adjunto]['tipo']);
         $mail->AddAttachment($archivo, $this->adjuntos[$id_adjunto]['nombre'], 'base64', $tipo);
     }
     $exito = $mail->Send();
     toba::logger()->debug("Enviado mail con asunto {$this->asunto} a {$this->hacia}");
     //Elimina los temporales creado para los attachments
     foreach ($temporales as $temp) {
         unlink($temp);
     }
     if (!$exito) {
         throw new toba_error("Imposible enviar mail. Mensaje de error: {$mail->ErrorInfo}");
     }
 }