Sunday, December 30, 2018

php - Postfix screwing up email headers!



I've set up a local dev environment on snow leopard, and have set postfix up to send email via my isp mail server.



I eventually got postfix to work after much frustration, but now when my emails send the header information is bunged up!




I'm using the following php code:




$email = "me@mydomain";
$subject = "Email tester";
$body = "Simple test";
$header = "From: me@mydomain \r\n";
$header .= "MIME-VERSION: 1.0\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$phpversion = phpversion();
$header .= "X-Mailer: PHP v$phpversion\r\n";
mail($email,$subject,$body,$header);

echo "message sent!";


The To: and Subject: headers display as they should, in the header!, but the rest display in the email body. This makes the email look like the from field in email client is empty.



I've tried a variety of php scripts, some very simple, but its the same thing, headers always displaying in the email body.




I'm thinking it could be a postfix problem, but not sure, anyone encountered this type of problem before?


Answer



Use PHP_EOL instead of \r\n in *additional_headers*, i.e. $header in your example. PHP_EOL will substitute the newline correspondingly to the OS you are running on.



Also, message should contain LN only i.e. \n. This is accordingly to PHP documentation.
Each line should be separated with a LF (\n). Lines should not be larger than 70 characters.



Make sure you meet both of criterias in your script - I've tried to achieve it and finally got it working with the default configuration of Postfix.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...