I am having some serious problem with some e-mail issue.
in short:
- loading a html template file
fopen - replacing some values, marked like this
%passwordwith real valuesstr_replace - sending mail via the following function, where
$contentis the loaded html template file:
public function send($receiver, $subject, $content){
$header = "From:".sender. "\n";
$header .= "MIME-Version:1.0" . "\n";
$header .= "Content-type:text/html;charset=utf-8" . "\n";
$mailText = $content;
mail($receiver, $subject, stripslashes(iconv('utf-8', 'iso-8859-1', $mailText)) , $header);
}
the server is debian with postfix.
The Mail template starts with
<html> <body style="background-color: #fff;"> <table border="0"...
The thing is, and I cannot reproduce it, that in some cases I can find several spaces in the mail, which I didn’t put there. Most problematical are those in the user and password string.
Evering else seems correct! The encoding is ok, the html is accepted, all mails can be delivered …
password generation:
public static function create_password($length = 12) {
$characters = array("a", "b", "c", "d", "e", "f", "g", "h", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "_");
$password = "";
for($i=0; $i<$length; $i++) {
$index = rand(1, count($characters)) -1;
$password .= $characters[$index];
}
$password = str_replace("__","_", $password);
return $password;
}
Any Ideas, where to start my search?
Is it the template, str_replace, the postifix, the client, … ?
Thanks so far
I would start by saving the HTML into a separate file and open that with a browser.
Mangling
This is often caused because your lines are simply too long and mail servers do funky stuff with lines longer than 80 columns (ancient standards).
To prevent mangling I would suggest the following:
Add header
Content-Transfer-Encoding: base64.Apply
chunk_split(base64_encode(...))over the whole e-mail content.