Cómo evitar el correo spam () en PHP

  • diyath
  • Newbie
  • Newbie
  • No Avatar
  • Registrado: Oct 13, 2010
  • Mensajes: 5
  • Status: Offline

Nota Octubre 22nd, 2010, 10:29 pm

Puedo usar esta clase enviar correo electrónico, pero se han ido como spam

PHP Código: [ Select ]
<?php
/***
   Email addresses can validate using email_validation(...) method.
   
   This class is use to send mails to valid email address(es)
   by calling methods as following order,
   1) set_header(.....)
   2) set_body(...)
   3) send_mail(.....)
***/
 
class GenerateMails{
   private $headers = array();
   private $recipients;
   private $contenttype;
   private $subject;
   private $email_msg;
   private $hdr;
   
   public $msg;
 
   
   /* This function use for validate email address(es).
      para :
         $email_addrses = This can be list of email addresses seperated by commas
                      or email addresses array
      return :
         true/false
   */
   public function email_validation($email_addrses)
   {
      $validate = true;
      if(!is_array($email_addrses))
      {
         $email_arry = explode(',',$email_addrses);
         $validate=$this->chk_email_arry($email_arry);
      }
      else
      {
         $validate=$this->chk_email_arry($email_addrses);
      }
      return $validate;
   }
   
 
   /* This function use for generate msg for email address(es)
      para :
         $email_arry = Email array
      return :
         true/false
   */
   private function chk_email_arry($email_arry)
   { 
      $rtn_val=true;
      foreach($email_arry as $val)
      {
         if(!filter_var($val,FILTER_VALIDATE_EMAIL))
         {
            $this->msg .= $val.' - Invalid Email Address.<br />';
            $rtn_val=false;  
         }
      }
      return $rtn_val;
   }
 
 
   /* This function use to set sender email & name
      para :
         $email = sender email
         $name = sender name
   */
   private function from($email,$name)
   {
       @ini_set('sendmail_from','test');
       $this->headers[] = 'From: '.$email.' <'.$name.'>';
   }
 
 
   /* This function use to set reply to email & name
      para :
         $email = Reply email
         $name = Reply name
   */
   private function reply_to($rplyto_email,$rplyto_name)
   {
       $this->headers[] = 'Reply-To: '.$rplyto_email.' <'.$rplyto_name.'>';
   }
 
 
   /* This function is use for add reciepients.
      para :
         $recipient_list = recipient list should separate by comma.
   */
    private function add_recipient($recipient_list)
    {  
      $this->recipients =$recipient_list;
    }
   
 
   /* This function is use for add CC.
      para :
         $cc_address_list = cc address list should separate by comma.
   */
    private function set_cc($cc_address_list)
    {
      $this->headers[] = "CC: ".$cc_address_list;
    }
   
 
   /* This function is use for add BCC.
      para :
         $bcc_address_list = BCC address list should separate by comma.
   */
    private function set_bcc($bcc_address_list)
    {
      $this->headers[] = "BCC: ".$bcc_address_list;
    }
   
 
 
   /* This function use to set header values.
      para :
         $header_type = normal - without attachment
                      attachment - with attachment
         $ishtml = true - content type is HTML
                  false - content is plain text
   */
   public function mail_header($header_type, $ishtml = true)
   {
      $this->headers[]  = "MIME-Version: 1.0";
     
      switch($header_type)
      {
         case "normal":
            if ($ishtml) {
               $this->contenttype = "text/html";
            } else {
               $this->contenttype = "text/plain";
            }
             $this->headers[]  = "Content-type: ".$this->contenttype."; charset=UTF-8";
         break;
         
         case "attachment":
            $semi_rand = md5(time());
            $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
           
             $this->headers[]  = "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
         break;
         
      }
   }
   
   
   /* This function use to set priorities
   */
   private function priority()
   {
       $this->headers[]  = "X-Priority: 3";
       $this->headers[]  = "X-Mailer: php";
   }
   
 
   /* This function use to set mail subject.
   */
   private function set_subject($subject)
   {
      $this->subject = $subject;
   }
   
 
   /* This function use to set mail attachmant(s)
      para :
         $attfile = file name(s) array
   */
   private function set_attachment($attfile)
   {
      $semi_rand = md5(time());
      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
   
      // preparing attachments
      $file = fopen($attfile,"rb");
      $data = fread($file,filesize($attfile));
      fclose($file);
     
      $data = chunk_split(base64_encode($data));
     
      $message = "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$attfile\"\n" .
      "Content-Disposition: attachment;\n" . " filename=\"$attfile\"\n" .
      "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
      $message .= "--{$mime_boundary}\n";
 
      return $message;
   }
   
   
   /* This function use to set mail header
      para :
         $header_type = normal - without attachment
                      attachment - with attachment
         $ishtml = true - content type is HTML
                  false - content is plain text
         $from_email = from email address
         $from_name = from name
         $recipient_list = recipient email(s) seperated by commas
         $cc_address_list = CC email(s) seperated by commas
         $bcc_address_list = BCC email(s) seperated by commas
         $subject = email subject
   */
   public function set_header($header_type, $ishtml=true, $from_email, $from_name, $rplyto_email, $rplyto_name,$recipient_list, $cc_address_list, $bcc_address_list, $subject)
   {
      $this->mail_header($header_type, $ishtml=true);
      $this->priority();
      $this->from($from_email,$from_name);
      $this->reply_to($rplyto_email,$rplyto_name);
      $this->add_recipient($recipient_list);
      $this->set_cc($cc_address_list);
      $this->set_bcc($bcc_address_list);
      $this->set_subject($subject);
   }
   
   
   /* This function use to set mail body
      para :
         $email_msg = massege
         $email_msg_type = normal - without attachment
                    attachment - with attachment
         $attfile = file name(s) array
   */
   public function set_body($email_msg,$email_msg_type,$attfile)
   {
     
      switch($email_msg_type)
      {
         case "normal":
            $this->email_msg = wordwrap($email_msg,70);
         break;
         
         case "attachment":
         
            $semi_rand = md5(time());
            $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
     
            $this->email_msg = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_msg . "\n\n";
            $this->email_msg .= "--{$mime_boundary}\n";
           
            if(is_array($attfile))
            {
               for($x=0;$x<count($attfile);$x++)
               {
                  if(file_exists($attfile[$x]))
                  {
                     $this->email_msg .= $this->set_attachment($attfile[$x]);
                  }
                  else
                  {
                     $this->email_msg .= ' No Data found for the file '.$attfile[$x]."--{$mime_boundary}\n";
                  }
               }
            }
/*          else
            {
               $this->email_msg = $this->set_attachment($attfile);
            }
*/
         break;
      }
      $this->email_msg = wordwrap($this->email_msg,70);
   }
   
   
   /* This function use to send mail
      return :
         treu/false
   */
   public function send_mail()
   {
      $this->hdr = implode("\r\n",$this->headers);
      unset($this->headers);
      return mail($this->recipients, $this->subject, $this->email_msg, $this->hdr);
   }
}
 
?>
  1. <?php
  2. /***
  3.    Email addresses can validate using email_validation(...) method.
  4.    
  5.    This class is use to send mails to valid email address(es)
  6.    by calling methods as following order,
  7.    1) set_header(.....)
  8.    2) set_body(...)
  9.    3) send_mail(.....)
  10. ***/
  11.  
  12. class GenerateMails{
  13.    private $headers = array();
  14.    private $recipients;
  15.    private $contenttype;
  16.    private $subject;
  17.    private $email_msg;
  18.    private $hdr;
  19.    
  20.    public $msg;
  21.  
  22.    
  23.    /* This function use for validate email address(es).
  24.       para :
  25.          $email_addrses = This can be list of email addresses seperated by commas
  26.                       or email addresses array
  27.       return :
  28.          true/false
  29.    */
  30.    public function email_validation($email_addrses)
  31.    {
  32.       $validate = true;
  33.       if(!is_array($email_addrses))
  34.       {
  35.          $email_arry = explode(',',$email_addrses);
  36.          $validate=$this->chk_email_arry($email_arry);
  37.       }
  38.       else
  39.       {
  40.          $validate=$this->chk_email_arry($email_addrses);
  41.       }
  42.       return $validate;
  43.    }
  44.    
  45.  
  46.    /* This function use for generate msg for email address(es)
  47.       para :
  48.          $email_arry = Email array
  49.       return :
  50.          true/false
  51.    */
  52.    private function chk_email_arry($email_arry)
  53.    { 
  54.       $rtn_val=true;
  55.       foreach($email_arry as $val)
  56.       {
  57.          if(!filter_var($val,FILTER_VALIDATE_EMAIL))
  58.          {
  59.             $this->msg .= $val.' - Invalid Email Address.<br />';
  60.             $rtn_val=false;  
  61.          }
  62.       }
  63.       return $rtn_val;
  64.    }
  65.  
  66.  
  67.    /* This function use to set sender email & name
  68.       para :
  69.          $email = sender email
  70.          $name = sender name
  71.    */
  72.    private function from($email,$name)
  73.    {
  74.        @ini_set('sendmail_from','test');
  75.        $this->headers[] = 'From: '.$email.' <'.$name.'>';
  76.    }
  77.  
  78.  
  79.    /* This function use to set reply to email & name
  80.       para :
  81.          $email = Reply email
  82.          $name = Reply name
  83.    */
  84.    private function reply_to($rplyto_email,$rplyto_name)
  85.    {
  86.        $this->headers[] = 'Reply-To: '.$rplyto_email.' <'.$rplyto_name.'>';
  87.    }
  88.  
  89.  
  90.    /* This function is use for add reciepients.
  91.       para :
  92.          $recipient_list = recipient list should separate by comma.
  93.    */
  94.     private function add_recipient($recipient_list)
  95.     {  
  96.       $this->recipients =$recipient_list;
  97.     }
  98.    
  99.  
  100.    /* This function is use for add CC.
  101.       para :
  102.          $cc_address_list = cc address list should separate by comma.
  103.    */
  104.     private function set_cc($cc_address_list)
  105.     {
  106.       $this->headers[] = "CC: ".$cc_address_list;
  107.     }
  108.    
  109.  
  110.    /* This function is use for add BCC.
  111.       para :
  112.          $bcc_address_list = BCC address list should separate by comma.
  113.    */
  114.     private function set_bcc($bcc_address_list)
  115.     {
  116.       $this->headers[] = "BCC: ".$bcc_address_list;
  117.     }
  118.    
  119.  
  120.  
  121.    /* This function use to set header values.
  122.       para :
  123.          $header_type = normal - without attachment
  124.                       attachment - with attachment
  125.          $ishtml = true - content type is HTML
  126.                   false - content is plain text
  127.    */
  128.    public function mail_header($header_type, $ishtml = true)
  129.    {
  130.       $this->headers[]  = "MIME-Version: 1.0";
  131.      
  132.       switch($header_type)
  133.       {
  134.          case "normal":
  135.             if ($ishtml) {
  136.                $this->contenttype = "text/html";
  137.             } else {
  138.                $this->contenttype = "text/plain";
  139.             }
  140.              $this->headers[]  = "Content-type: ".$this->contenttype."; charset=UTF-8";
  141.          break;
  142.          
  143.          case "attachment":
  144.             $semi_rand = md5(time());
  145.             $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  146.            
  147.              $this->headers[]  = "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
  148.          break;
  149.          
  150.       }
  151.    }
  152.    
  153.    
  154.    /* This function use to set priorities
  155.    */
  156.    private function priority()
  157.    {
  158.        $this->headers[]  = "X-Priority: 3";
  159.        $this->headers[]  = "X-Mailer: php";
  160.    }
  161.    
  162.  
  163.    /* This function use to set mail subject.
  164.    */
  165.    private function set_subject($subject)
  166.    {
  167.       $this->subject = $subject;
  168.    }
  169.    
  170.  
  171.    /* This function use to set mail attachmant(s)
  172.       para :
  173.          $attfile = file name(s) array
  174.    */
  175.    private function set_attachment($attfile)
  176.    {
  177.       $semi_rand = md5(time());
  178.       $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  179.    
  180.       // preparing attachments
  181.       $file = fopen($attfile,"rb");
  182.       $data = fread($file,filesize($attfile));
  183.       fclose($file);
  184.      
  185.       $data = chunk_split(base64_encode($data));
  186.      
  187.       $message = "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$attfile\"\n" .
  188.       "Content-Disposition: attachment;\n" . " filename=\"$attfile\"\n" .
  189.       "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
  190.       $message .= "--{$mime_boundary}\n";
  191.  
  192.       return $message;
  193.    }
  194.    
  195.    
  196.    /* This function use to set mail header
  197.       para :
  198.          $header_type = normal - without attachment
  199.                       attachment - with attachment
  200.          $ishtml = true - content type is HTML
  201.                   false - content is plain text
  202.          $from_email = from email address
  203.          $from_name = from name
  204.          $recipient_list = recipient email(s) seperated by commas
  205.          $cc_address_list = CC email(s) seperated by commas
  206.          $bcc_address_list = BCC email(s) seperated by commas
  207.          $subject = email subject
  208.    */
  209.    public function set_header($header_type, $ishtml=true, $from_email, $from_name, $rplyto_email, $rplyto_name,$recipient_list, $cc_address_list, $bcc_address_list, $subject)
  210.    {
  211.       $this->mail_header($header_type, $ishtml=true);
  212.       $this->priority();
  213.       $this->from($from_email,$from_name);
  214.       $this->reply_to($rplyto_email,$rplyto_name);
  215.       $this->add_recipient($recipient_list);
  216.       $this->set_cc($cc_address_list);
  217.       $this->set_bcc($bcc_address_list);
  218.       $this->set_subject($subject);
  219.    }
  220.    
  221.    
  222.    /* This function use to set mail body
  223.       para :
  224.          $email_msg = massege
  225.          $email_msg_type = normal - without attachment
  226.                     attachment - with attachment
  227.          $attfile = file name(s) array
  228.    */
  229.    public function set_body($email_msg,$email_msg_type,$attfile)
  230.    {
  231.      
  232.       switch($email_msg_type)
  233.       {
  234.          case "normal":
  235.             $this->email_msg = wordwrap($email_msg,70);
  236.          break;
  237.          
  238.          case "attachment":
  239.          
  240.             $semi_rand = md5(time());
  241.             $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  242.      
  243.             $this->email_msg = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_msg . "\n\n";
  244.             $this->email_msg .= "--{$mime_boundary}\n";
  245.            
  246.             if(is_array($attfile))
  247.             {
  248.                for($x=0;$x<count($attfile);$x++)
  249.                {
  250.                   if(file_exists($attfile[$x]))
  251.                   {
  252.                      $this->email_msg .= $this->set_attachment($attfile[$x]);
  253.                   }
  254.                   else
  255.                   {
  256.                      $this->email_msg .= ' No Data found for the file '.$attfile[$x]."--{$mime_boundary}\n";
  257.                   }
  258.                }
  259.             }
  260. /*          else
  261.             {
  262.                $this->email_msg = $this->set_attachment($attfile);
  263.             }
  264. */
  265.          break;
  266.       }
  267.       $this->email_msg = wordwrap($this->email_msg,70);
  268.    }
  269.    
  270.    
  271.    /* This function use to send mail
  272.       return :
  273.          treu/false
  274.    */
  275.    public function send_mail()
  276.    {
  277.       $this->hdr = implode("\r\n",$this->headers);
  278.       unset($this->headers);
  279.       return mail($this->recipients, $this->subject, $this->email_msg, $this->hdr);
  280.    }
  281. }
  282.  
  283. ?>
Moderator Remark: added [code] tags
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Octubre 22nd, 2010, 10:29 pm

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • Avatar de Usuario
  • Registrado: Dic 20, 2002
  • Mensajes: 8925
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Nota Octubre 23rd, 2010, 10:33 am

Cuando dices que los correos son "ido como spam", lo que significa que el correo electrónico no es aún capaz de ser enviado, ya que vuelve con un error? ¿O es que el correo electrónico se envían a su destino, pero el correo electrónico se muestra en la carpeta de spam o de distribución masiva? ¿Podría ser más específico a qué se refiere?
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • diyath
  • Newbie
  • Newbie
  • No Avatar
  • Registrado: Oct 13, 2010
  • Mensajes: 5
  • Status: Offline

Nota Octubre 24th, 2010, 7:48 pm

el correo electrónico se envían a mi destino, pero el correo electrónico se muestra en el spam
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • Avatar de Usuario
  • Registrado: May 22, 2004
  • Mensajes: 3415
  • Loc: Richland, WA
  • Status: Offline

Nota Octubre 25th, 2010, 7:18 am

Eso podría ser un par de cosas.

Lo primero que puede hacer es asegurarse de que su envío de las cabeceras adecuadas, junto con su correo electrónico. Lo siguiente sería comprobar para ver si su servidor IP ha sido negro en la lista.

http://whatismyipaddress.com/blacklist-check
#define NULL (::rand() % 2)
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • Avatar de Usuario
  • Registrado: Dic 20, 2002
  • Mensajes: 8925
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Nota Octubre 25th, 2010, 11:40 am

Para el e-mail a su destino en el que está apareciendo como spam, yo sugeriría mirar los encabezados de correo electrónico no para ver si algo se destaca, como no las comprobaciones SPF, o cualquier otras etiquetas que podría indicar por qué su ser etiquetado como spam. También me gustaría ver todas las direcciones IP en los encabezados, además de su propia para ver si están en listas negras como falsos mencionados. A veces, cuando se envía por e-mail a cabo pasan por un servidor SMTP que es la lista negra por lo que me gustaría ver más direcciones IP que sólo la suya.
Ozzu Hosting - Want your website on a fast server like Ozzu?

Publicar Información

  • Total de mensajes en este tema: 5 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 223 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC