function mail headers already sent, wat gaat er mis?

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Eric T

Eric T

23/04/2014 00:31:05
Quote Anchor link
Ben een beetje flabberguested...

Ik heb een script waarin ik include sendmailnoattach.php
Hierin staat de volgende functie:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
function sendMailNoAtt($mailaddress,$from,$frommail,$subject,$message){

    //Would you like to send a bcc too?
        $emailtoo= ""; // Who the email Bcc is send too
    //Other stuff

        $boundary = rand(1000000, 9999999);
    
    
    // additional headers at the beginning
        $headers  = "MIME-Version: 1.0\r\n";
        $headers .= "From: $from <$frommail>\r\n";
        $headers .= "Reply-To: <$frommail>\r\n";
        $headers .= "Bcc: $emailtoo \r\n";
        $headers .= "Content-Type: text/html;charset=\"iso-8859-1\"; boundary=\"todd$boundary\"";
    
    
    //Here will be the message
        $mailBody .= "--todd$boundary\n";
        $mailBody .= "Content-Type: text/html; charset=iso-8859-1\n";
        $mailBody .= "Content-Transfer-Encoding: 7bit\n\n";
        $mailBody .= "$message\n\n";
        $mailBody .= "Content-transfer-encoding: base64\n\n";     
        
        $mailBody .= "\n\n--todd$boundary--\n";
        
        
    // send email
        
        mail($mailaddress, $subject, $mailBody, $headers);
        echo "Mail is verzonden aan: ".$email."<br>";

}

?>


Als ik de pagina oproep (index.php), krijg ik de volgende melding:

Warning: Cannot modify header information - headers already sent by (output started at /public/sites/.../sendmailnoattach.php:46)

Ter info, als ik i.p.v. een zelfde functie maar dan mét attachment kies/uitvoer/include
is er geen enkel probleem...

Iemand enig idee?
 
PHP hulp

PHP hulp

24/04/2024 23:26:56
 
- Ariën  -
Beheerder

- Ariën -

23/04/2014 00:32:31
Quote Anchor link
In sendmailnoattach.php op lijn 46 heb je HTML-output staan of een witregel, en dat mag niet voor een header(), setcookie() of session_start().
 
Eric T

Eric T

23/04/2014 00:34:43
Quote Anchor link
Noaoaoaoaoaoahhhh.... Zo veel dank Aar!!!!
Inderdaad, na de sluittag stonde drie witregels :-(
Het werkt nu! :-)
 
- Ariën  -
Beheerder

- Ariën -

23/04/2014 00:46:00
Quote Anchor link
Graag gedaan :-)
 
Ivo P

Ivo P

23/04/2014 08:58:22
Quote Anchor link
tip:
gebruik geen sluittag aan het einde van je scripts, dat voorkomt deze fout.
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.