hi guys,
i need help on this one. i am trying to send plain text mail with php and on some/most servers it simply does not get through- the mail gets rejected as bad mail or something (but not as spam). i have tried anything i could find on the internet but no luck till now.
i tried just mail($to,$subject, $msg)
the same thing but with $headers-
tried most of them in many kinds of orderings,
with or without spaces/crlf/lf and so on
i tried the pear mail class- with smtp and sendmail
and nothing seems to work.
here's some code
include('Mail.php');
$recipients = 'some@mail.com';
$headers['MIME-Version'] = '1.0';
$headers['Content-Type'] = 'text/plain; charset="iso-8859-1';
$headers['From'] = 'me@server.com';
$headers['To'] = 'some@mail.com';
$headers['Reply-To'] = 'me@server.com';
$headers['X-Mailer'] = 'PHP';
$headers['Subject'] = 'Test message';
$body = 'Test message';
// for 'smtp'
$param["host"] = 'localhost';
$param["port"] = 25;
$param["auth"] = false;
// for 'sendmail'
$params['sendmail_path'] = '/usr/sbin/sendmail';
// $params['sendmail_path'] = '/usr/sbin/sendmail -t -i -F [email]admin@server.com[/email] -f [email]admin@server.com[/email]';
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('sendmail', $params);
$result = $mail_object->send($recipients, $headers, $body);
if($result) echo 'ok'; else echo PEAR_Error::toString();
$mail_object =& Mail::factory('smtp', $param);
$result = $mail_object->send($recipients, $headers, $body);
if($result) echo 'ok'; else echo PEAR_Error::toString();
$headers = "From: [email]me@server.com[/email]\n";
$headers .= "Reply-To: [email]me@server.com[/email]\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-Mailer: PHP Mailer\n";
$result = mail('some@mail.com', 'test mail', 'msg', $headers);
if($result) echo 'ok'; else echo 'error';