mail() not sending when adding headers.
I have a script that gets email addresses from a db and sends them. I can send them and have clients receive them when there are no headers sent with it. but I want to send html emails also so I need headers and when I send it that way the clients never receive the email and I dont get any errors.
PHP Code:
$boundary = md5(uniqid(time()));
$headers = 'From: ' . $from . "\n";
$headers .= 'To: ' . $myrow[email] . "\n";
$headers .= 'Return-Path: ' . $from . "\n";
$headers .= 'MIME-Version: 1.0' ."\n";
$headers .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '"' . "\n\n";
$headers .= $message . "\n";
$headers .= '--' . $boundary . "\n";
$headers .= 'Content-Type: text/plain; charset=ISO-8859-1' ."\n";
$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\n";
$headers .= $message . "\n";
$headers .= '--' . $boundary . "\n";
$headers .= 'Content-Type: text/HTML; charset=ISO-8859-1' ."\n";
$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\n";
$headers .= $message . "\n";
$headers .= '--' . $boundary . "--\n";
$mailOk=mail('', $subject,'', $headers);
Anyone have any ideas why?
Re: mail() not sending when adding headers.
You need to use the carrige return / linefeed combination to separate headers "\r\n". You should also add to the message argument "This is an MIME Encoded message".
Also, Return-Path cannot be set. This is set by the SMTP server and thus you need to set the sendmail_from PHP.ini setting using the init_set() function to change this to the value you wish.