472,364 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

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.

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
2 1786
Markus
6,050 Expert 4TB
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
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

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

Similar topics

1
by: Justin Haygood | last post by:
I want to use multiple custom headers in the mail() function. I know the basic syntax is mail(recipient, subject, content, optional headers). How would I use like say 3 headers? Also, what would...
0
by: Hal Vaughan | last post by:
I'm working with javax.mail.*. I have no problem with reading in messages. I'm not using multi-part messages or anything, I just use this setup: Session oSession =...
5
by: Simran | last post by:
I need to set up an automated email system , which means users should not be able to respond back to the emails but at the same time, we need to track bounced emails. This is important as our...
71
by: Christopher Benson-Manica | last post by:
At what point was the .h dropped from the STL headers? I just had a discussion yesterday with my boss, who said he wanted .h on all the STL includes, despite me protesting that it was not...
0
by: john bailo | last post by:
I am attempting to create a c# program to iterate through the messages in an Outlook/Exchange public folder and extract the headers. My apologies to the VB/VBA groups, but you seem to have more...
0
by: CFloyd | last post by:
I have a web service client that sends an XML string to the web service for processing. I alos have to add some headers to the post. I first establish the baseuri as === baseuri = new...
22
by: Platero | last post by:
Hi, I've a stupid question but... The code is the following: if(($role!='tutor')&&(array_key_exists('tutor_id',$_GET))) { $possible_ids = array(2,6,7,8,9,10); $t_id = $_GET;
8
by: Spartacus | last post by:
Oops, I meant to write: function send_mail($to_name, $to_email, $from_name, $from_email, $subject, $message) { $thedate = date("r", time()); $headers = "X-Mailer: PHPMailProgram/1.0\n";...
4
by: sadieslc | last post by:
I'm working on a PHP script, and the info from the form shows up in the headers of the email that I receive, but it doesn't show up in the body of the email. Can you please help me figure out what...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.