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";
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?
Re: mail() not working with headers
try using a carriage return as well as a new line character:
but, Samba's suggestion could also be the problem.
Re: mail() not working with headers
Quote:
Originally Posted by
solitario
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 :wave: