headers not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • urbanedge
    New Member
    • Apr 2009
    • 4

    headers not working

    I've uploaded a site to a new server and now the headers in the mail function are not working to send the required email response. This is a newly acquired site and my php knowledge is at the beginner level. I've managed to list the headers that are being sent but I can't seem to find where or why the email won't work. I'd really appreciate some help checking to see if there is an error in one of the header lines or perhaps the redirection.

    Code:
    <?
    /*
        Name:           eMail
        Description:    Simple sending eMail in text and HTML with CC, BCC and attachment
        Version:        1.0
        last modified:  2004-05-14
         Leave this header in this file!
    */
    
    class eMail
    {
        var $to = array();
        var $cc = array();
        var $bcc = array();
        var $attachment = array();
        var $boundary = "";
        var $header = "";
        var $subject = "";
        var $body = "";
    
        function eMail($name,$mail)
        {
            $this->boundary = md5(uniqid(time()));
            $this->header .= "From: $name <$mail>\n";
        }
    
        function to($mail)
        {
        	$this->to[] = $mail;
        }
    
        function cc($mail)
        {
        	$this->cc[] = $mail;
        }
    
        function bcc($mail)
        {
        	$this->bcc[] = $mail;
        }
    
        function attachment($file)
        {
    		$this->attachment[] = $file;
        }
    
        function subject($subject)
        {
        	$this->subject = $subject;
        }
    
        function text($text)
        {
    	    $this->body = "Content-Type: text/plain; charset=ISO-8859-1\n";
    	    // try without this $this->body .= "Content-Transfer-Encoding: 8bit\n\n";
    	    $this->body .= $text."\n";
        }
    
        function html($html)
        {
    	    $this->body = "Content-Type: text/html; charset=ISO-8859-1\n";
    	    //$this->body .= "Content-Transfer-Encoding: quoted-printable\n\n";
    	    //$this->body .= "<html><body>\n".$html."\n</body></html>\n";
    	    $this->body .= "\n".$html."\n\n";
        }
    
    	function send()
        {
            // CC Empfänger hinzufügen
            $max = count($this->cc);
            if($max>0)
            {
                $this->header .= "Cc: ".$this->cc[0];
                for($i=1;$i<$max;$i++)
                {
                    $this->header .= ", ".$this->cc[$i];
                }
                $this->header .= "\n";
            }
            // BCC Empfänger hinzufügen
            $max = count($this->bcc);
            if($max>0)
            {
                $this->header .= "Bcc: ".$this->bcc[0];
                for($i=1;$i<$max;$i++)
                {
                    $this->header .= ", ".$this->bcc[$i];
                }
                $this->header .= "\n";
            }
            $this->header .= "MIME-Version: 1.0\n";
    	    $this->header .= "Content-Type: multipart/mixed; boundary=$this->boundary\r\n";
    	    $this->header .= "This is a multi-part message in MIME format\n";
            $this->header .= "--$this->boundary\n";
            $this->header .= $this->body;
    
            // Attachment hinzufügen
            $max = count($this->attachment);
            if($max>0)
            {
                for($i=0;$i<$max;$i++)
                {
                    $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i]));
                    $this->header .= "--".$this->boundary."\n";
                    $this->header .= "Content-Type: application/x-zip-compressed; name=".$this->attachment[$i]."\n";
                    $this->header .= "Content-Transfer-Encoding: base64\n";
                    $this->header .= "Content-Disposition: attachment; filename=".$this->attachment[$i]."\r\n";
                    $this->header .= chunk_split(base64_encode($file))."\n";
                    $file = "";
                }
            }
            $this->header .= "--".$this->boundary."--\r\n";
    
            foreach($this->to as $mail)
            {
               // print ("<pre>" .$this->header. "<pre>");
                mail ($mail, $this->subject,"", $this->header);
            }
        }
    }
    ?>
    When the email is sent this is what is output for the headers:

    From: with domain name
    Bcc: with email
    MIME-Version: 1.0
    Content-Type: multipart/mixed; boundary=1220aa be3151c7827740f bbfd644047d

    This is a multi-part message in MIME format
    --1220aabe3151c78 27740fbbfd64404 7d
    Content-Type: text/html; charset=ISO-8859-1

    at the bottom of the email output the boundary is output again and

    Warning: cannot modify header information - headers already sent by (output started at "the name of this file is listed here)???

    I don't know where to go from here. It seems to be finding the includes file but then I get the Warning message. Should output buffering be added to the includes files? I'm not sure what headers to try and fix or comment out. I would really appreciate some help. I'm trying to figure out the importance of each header but I'm confused by what is necessary to allow the email to be sent.
    Last edited by Markus; Apr 24 '09, 03:54 PM. Reason: Added [code] tags.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    The error will have given you a number, too. More specifically, a line number. Can you tell us that please?

    Also, when posting code, please use [code] tags. Thank you.

    Comment

    • urbanedge
      New Member
      • Apr 2009
      • 4

      #3
      headers still not working

      Hi there,

      Here are the error msgs. When I add output buffering to the acciones_class_ confirmation_pr ofesores.php file it gets rid of the header error but the email is still not sending. I'm having a difficult time figuring out where to look for the errors. The help is greatly appreciated.



      Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in /home/content/c/a/n/canmex/html/teaching/acciones/class_mail.php on line 121

      Warning: Cannot modify header information - headers already sent by (output started at /home/content/c/a/n/canmex/html/teaching/acciones/class_mail.php: 121) in /home/content/c/a/n/canmex/html/teaching/acciones/acciones_class_ confirmation_pr ofesores.php on line 31



      Code:
      <?
      session_start();
      
      /****************** INCLUDES SRC************************/
      require_once "../../src/config/config.php";
      
      include ('../../src/common/base_datos/class.bd.php');
      include ('../../src/common/base_datos/funcManejo.php');
      
      include ('../../src/functions/procesar.php');
      include ('../../src/functions/estructurasTablas.php');
      
      include ('../../src/functions/imagenes.php');
      include ('../../src/functions/misc.php');
      
      /****************** INCLUDES FRONT************************/
      include ('../includes/functions_profesores.php');
      include ('../../includes/functions_alumnos.php'); 
      
      include ('../../function_generales/functions_generales_mail.php');
      include ('../../function_generales/functions_generales.php');
      $bd = crearConexion();
      
      $aClase = darDatosClase($_POST['id_clase']);
      
      switch ($_POST['accion']) {
          
      	case 'confirm':
      		if(cambiarEstadoClase($_POST['id_clase'], CLASE_ACEPTADA)){			
      			enviarEmail('clase_invitacion_confirmada', 'Your class is CONFIRMED!' , $aClase['alu_email'] , $aClase);
      			header("Location: ../mainProfesor.php"); die();
      		}
      		
          break;
      	
          case 'refuse': 
      		if(cambiarEstadoClase($_POST['id_clase'], CLASE_CANCELADA)){
      			enviarEmail('clase_invitacion_cancelada', 'Your class was NOT confirmed.' , $aClase['alu_email'] , $aClase);
      			header("Location: ../mainProfesor.php"); die();
      		}
          break;
      
      }
      ?>

      Comment

      Working...