Results 1 to 4 of 4

Thread: mail() not working with headers

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    121

    mail() not working with headers

    Hello all.
    Once I put in the following headers, mail() stopped working. When I take them out, it works. Any clues? Thanks.

    PHP Code:
    $headers='';
        
    $headers.='From: '.$sending_name.' <'.$sending_email.'>'."\n";
        
    $headers.='To: '.$array[0]['first_name'].' '.$array[0]['last_name'].' <'.$array[0]['txt_username'].'>'."\n";
        
    $headers.='Reply-To: '.$sending_name.' <'.$sending_email.'>'."\n";
        
    $headers.='Date: '.date("r")."\n";
        
    $headers.='Return-Path: '.$sending_name.' <'.$sending_email.'>'."\n";
        
    $headers.='MIME-Version: 1.0'."\n";
        
    $headers.='Content-type: text/html;charset=UTF-8'."\n"

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: mail() not working with headers

    Echo out $headers after all of your variables have been inserted and see if they're valid. On the "To:" line, is $array[0]['txt_username'] an email address?

  3. #3
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: mail() not working with headers

    try using a carriage return as well as a new line character:
    PHP Code:
    $headers .= "From: David Miles <[email protected]>\r\n"
    but, Samba's suggestion could also be the problem.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: mail() not working with headers

    Quote Originally Posted by solitario View Post
    Hello all.
    Once I put in the following headers, mail() stopped working. When I take them out, it works. Any clues? Thanks.

    PHP Code:
    $headers='';
        
    $headers.='From: '.$sending_name.' <'.$sending_email.'>'."\n";
        
    $headers.='To: '.$array[0]['first_name'].' '.$array[0]['last_name'].' <'.$array[0]['txt_username'].'>'."\n";
        
    $headers.='Reply-To: '.$sending_name.' <'.$sending_email.'>'."\n";
        
    $headers.='Date: '.date("r")."\n";
        
    $headers.='Return-Path: '.$sending_name.' <'.$sending_email.'>'."\n";
        
    $headers.='MIME-Version: 1.0'."\n";
        
    $headers.='Content-type: text/html;charset=UTF-8'."\n"
    As well as complying with the RFC 2821 and terminating headers with <CRLF>, you should also ensure that the variables you have inserted into the headers do not contain <CRLF> (especially if they originate from a user entered form).

    If you do not do this, a malicious user could insert their own headers (e.g. Cc:, Bcc: and attachments). Your web form could then be used as a spamming engine for Viagra pills
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width