php send mail problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Current, I have a function to send UTF-8 encoded HTML Format email to

But my found that the produced email sometime accidently being injected
with the ! sign.......

e.g. <td> sometime become <!td>

here is the code for that function

$sql = "select * from user where userid='$userid'";
$res = send_sql($sql);
//Get Reserve staff info
$row = mysql_fetch_array($res);
$fusername = $row["UserName"];
$femail = $row["Email"];
$message= ERNST."<html><body>";
$message.= "Hi ".htmlspecialchars($fusername).",<br><br>";
$message.= "Please note that the system accepted your borrowing of
files at ".date("d M Y H:i:s")."<br>";
$message.= "<br>";
$message.= "<table width='100%' border='1'>";
$message.= "<tr align='center'
Name</th><th>Client Code</th><th>Year
foreach ($fileid as $x) {
    $query  = "SELECT
    $query .= " FROM Client c, f_group g, f_folderlist fl,f_file f";
    $query .= " where fl.fileid='$x' and fl.fileid=f.fileid and
fl.clientid=c.clientid and c.grpid = g.gpid" ;
    $res2 = send_sql($query);
    while($row2 = mysql_fetch_array($res2)) {
        $cname .= $j . ": " .htmlspecialchars($row2["clientname"]);
        if ($j<=mysql_num_rows($res2)-1) $cname.="<br>";
        $gname = $row2["groupname"];
    $message.="<tr align='center'><td>".htmlspecialchars($x)."<td
} //endforeach
$message.= "</table>";
$message.= "<br>";
$message.="<table width='100%'><tr><td>Your truly,<BR>System
Administration/Operator<td align='right'>Date:
".htmlspecialchars(date("d M Y"))."</table>";
$message.= "</body></html>";
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";
@mail($femail, "Notify of File borrowing", $message,$headers);

Re: php send mail problem


on 11/17/2005 12:46 AM khng said the following:
Quoted text here. Click to load it

I think sendmail does that when the message body is not encoded  
properly. You need to encode the message body with quoted-printable  
encoding. You may want to try this MIME message class that can send your  
  message body with UTF-8 characters encoding them as quoted printable:


Manuel Lemos

Metastorage - Data object relational mapping layer generator

PHP Classes - Free ready to use OOP components written in PHP

Re: php send mail problem

Thank you for your ideal, finally I found the solution.

I hop that this is useful for other.

The injection of other symbol is due to the fact that the message is
too long without any line break character.

So inorder to kill that problem, I just add \r\n between every 50
character but not inside html tag

Site Timeline