By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,743 Members | 1,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,743 IT Pros & Developers. It's quick & easy.

headers not working

P: 4
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.

Expand|Select|Wrap|Line Numbers
  1. <?
  2. /*
  3.     Name:           eMail
  4.     Description:    Simple sending eMail in text and HTML with CC, BCC and attachment
  5.     Version:        1.0
  6.     last modified:  2004-05-14
  7.      Leave this header in this file!
  8. */
  9.  
  10. class eMail
  11. {
  12.     var $to = array();
  13.     var $cc = array();
  14.     var $bcc = array();
  15.     var $attachment = array();
  16.     var $boundary = "";
  17.     var $header = "";
  18.     var $subject = "";
  19.     var $body = "";
  20.  
  21.     function eMail($name,$mail)
  22.     {
  23.         $this->boundary = md5(uniqid(time()));
  24.         $this->header .= "From: $name <$mail>\n";
  25.     }
  26.  
  27.     function to($mail)
  28.     {
  29.         $this->to[] = $mail;
  30.     }
  31.  
  32.     function cc($mail)
  33.     {
  34.         $this->cc[] = $mail;
  35.     }
  36.  
  37.     function bcc($mail)
  38.     {
  39.         $this->bcc[] = $mail;
  40.     }
  41.  
  42.     function attachment($file)
  43.     {
  44.         $this->attachment[] = $file;
  45.     }
  46.  
  47.     function subject($subject)
  48.     {
  49.         $this->subject = $subject;
  50.     }
  51.  
  52.     function text($text)
  53.     {
  54.         $this->body = "Content-Type: text/plain; charset=ISO-8859-1\n";
  55.         // try without this $this->body .= "Content-Transfer-Encoding: 8bit\n\n";
  56.         $this->body .= $text."\n";
  57.     }
  58.  
  59.     function html($html)
  60.     {
  61.         $this->body = "Content-Type: text/html; charset=ISO-8859-1\n";
  62.         //$this->body .= "Content-Transfer-Encoding: quoted-printable\n\n";
  63.         //$this->body .= "<html><body>\n".$html."\n</body></html>\n";
  64.         $this->body .= "\n".$html."\n\n";
  65.     }
  66.  
  67.     function send()
  68.     {
  69.         // CC Empfänger hinzufügen
  70.         $max = count($this->cc);
  71.         if($max>0)
  72.         {
  73.             $this->header .= "Cc: ".$this->cc[0];
  74.             for($i=1;$i<$max;$i++)
  75.             {
  76.                 $this->header .= ", ".$this->cc[$i];
  77.             }
  78.             $this->header .= "\n";
  79.         }
  80.         // BCC Empfänger hinzufügen
  81.         $max = count($this->bcc);
  82.         if($max>0)
  83.         {
  84.             $this->header .= "Bcc: ".$this->bcc[0];
  85.             for($i=1;$i<$max;$i++)
  86.             {
  87.                 $this->header .= ", ".$this->bcc[$i];
  88.             }
  89.             $this->header .= "\n";
  90.         }
  91.         $this->header .= "MIME-Version: 1.0\n";
  92.         $this->header .= "Content-Type: multipart/mixed; boundary=$this->boundary\r\n";
  93.         $this->header .= "This is a multi-part message in MIME format\n";
  94.         $this->header .= "--$this->boundary\n";
  95.         $this->header .= $this->body;
  96.  
  97.         // Attachment hinzufügen
  98.         $max = count($this->attachment);
  99.         if($max>0)
  100.         {
  101.             for($i=0;$i<$max;$i++)
  102.             {
  103.                 $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i]));
  104.                 $this->header .= "--".$this->boundary."\n";
  105.                 $this->header .= "Content-Type: application/x-zip-compressed; name=".$this->attachment[$i]."\n";
  106.                 $this->header .= "Content-Transfer-Encoding: base64\n";
  107.                 $this->header .= "Content-Disposition: attachment; filename=".$this->attachment[$i]."\r\n";
  108.                 $this->header .= chunk_split(base64_encode($file))."\n";
  109.                 $file = "";
  110.             }
  111.         }
  112.         $this->header .= "--".$this->boundary."--\r\n";
  113.  
  114.         foreach($this->to as $mail)
  115.         {
  116.            // print ("<pre>" .$this->header. "<pre>");
  117.             mail ($mail, $this->subject,"", $this->header);
  118.         }
  119.     }
  120. }
  121. ?>
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=1220aabe3151c7827740fbbfd644047d

This is a multi-part message in MIME format
--1220aabe3151c7827740fbbfd644047d
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.
Apr 24 '09 #1
Share this Question
Share on Google+
2 Replies


Markus
Expert 5K+
P: 6,050
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.
Apr 24 '09 #2

P: 4
Hi there,

Here are the error msgs. When I add output buffering to the acciones_class_confirmation_profesores.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_profesores.php on line 31



Expand|Select|Wrap|Line Numbers
  1. <?
  2. session_start();
  3.  
  4. /****************** INCLUDES SRC************************/
  5. require_once "../../src/config/config.php";
  6.  
  7. include ('../../src/common/base_datos/class.bd.php');
  8. include ('../../src/common/base_datos/funcManejo.php');
  9.  
  10. include ('../../src/functions/procesar.php');
  11. include ('../../src/functions/estructurasTablas.php');
  12.  
  13. include ('../../src/functions/imagenes.php');
  14. include ('../../src/functions/misc.php');
  15.  
  16. /****************** INCLUDES FRONT************************/
  17. include ('../includes/functions_profesores.php');
  18. include ('../../includes/functions_alumnos.php'); 
  19.  
  20. include ('../../function_generales/functions_generales_mail.php');
  21. include ('../../function_generales/functions_generales.php');
  22. $bd = crearConexion();
  23.  
  24. $aClase = darDatosClase($_POST['id_clase']);
  25.  
  26. switch ($_POST['accion']) {
  27.  
  28.     case 'confirm':
  29.         if(cambiarEstadoClase($_POST['id_clase'], CLASE_ACEPTADA)){            
  30.             enviarEmail('clase_invitacion_confirmada', 'Your class is CONFIRMED!' , $aClase['alu_email'] , $aClase);
  31.             header("Location: ../mainProfesor.php"); die();
  32.         }
  33.  
  34.     break;
  35.  
  36.     case 'refuse': 
  37.         if(cambiarEstadoClase($_POST['id_clase'], CLASE_CANCELADA)){
  38.             enviarEmail('clase_invitacion_cancelada', 'Your class was NOT confirmed.' , $aClase['alu_email'] , $aClase);
  39.             header("Location: ../mainProfesor.php"); die();
  40.         }
  41.     break;
  42.  
  43. }
  44. ?>
Apr 27 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.