Question

I am struggling with this issue for few days now, reading and trying whatever I came across with no solution found: Here is the bottom line of what I want to do: I have a members only system. when a member posts a message on the message board all others get notification by email. Simple. I use the PHP script to create a list of recipients (email and name) in a CSV file, store the file to be opened later by the cron job and shoot the emails out. Simple. Oh ... names are in Hebrew script as they stored in the MySQL DB. I have tried the script manually (running it through the browser and it all went sweet). Running it through cron, though, will not read the names and leave it blank:

while($arrMailAttrib = fgetcsv($hFile))
{
    $sAptName   = $arrMailAttrib[0];
    $sAptNum    = $arrMailAttrib[1];
    $sTo        = $arrMailAttrib[2];
    $sSubject   = $arrMailAttrib[3];
    $sMsgURL    = $arrMailAttrib[4];
    $sBody      = "<span style=\"font-family: Arial, Helvetica, sans-serif; direction: rtl !important; vertical-align: right; display: block;\" lang=\"he\" dir=\"rtl\"> <p>שלום $sAptName (מספר חבר $sAptNum),</p> <p>הודעה חדשה בנושא '$sSubject' נוצרה בלוח המודעות הוירטואלי.</p> <p>על מנת לצפות בהודעה ישירות במערכת <a href=\"$sMsgURL\">כאן</a></p> <p>על מנת להכנס למערכת  הכנס ל: <a href=\"http://www.somesite.com\">http://www.somesite.com</a> </p> <p><font size=\"-1\" color=\"#999999\">זוהי הודעת אימייל אוטומטית. נא לא להגיב לכתובת אימייל זו.</font></p> <p>&nbsp;</p> </span>";
    if(defined('_DEBUG_')) {fputs($hLogFile, "sending email with subject '$sSubject' to $sTo\n");}
    mail($sTo, $sSubject, $sBody, $sHeaders);
}

The CSV is being created with the names and email straight as it was brought from the DB. I am positive that this has something to do with the encoding - but I just seem not to be able to put my finger on what exactly. here is few lines from the CSV file: שמואלי,

1,בהיר,someone1@gmail.com,הודעה נסיונית,http://www.somesite.com/_new.message_present.php?fldMsg=111
    כהן,2,someone2@gmail.com,הודעה נסיונית,http://vwww.somesite.com/_new.message_present.php?fldMsg=112
    שפיר,4,someone3@hotmail.com,הודעה נסיונית,http://www.somesite.com/_new.message_present.php?fldMsg=113
    ליבוביץ,5,someone4@metis.asia,הודעה נסיונית,http://www.somesite.com/_new.message_present.php?fldMsg=114

One more thing that is worth noteing is that I get an error to my email from the cron job with just the text: "Content-type:text/html"

By the way - the emails get just fine to the recipients, the body of the email show in Hebrew. The only things missing are subject and name.

Anyone ...?

Was it helpful?

Solution 2

Ok, found a solution to it. This goes for all of you who encounter a similar problem not necessarily with Hebrew, but with any other multibyte language: fgetcsv does not support multibyte. Hence, it will never read Hebrew. Step one was that I had to write the file with fwrite and read it with fread instead of using fputcsv and fgetcsv. Step two was to use mb_send_mail() function instead of the plain mail() function, and before calling it, setting the mb_language('he') and mb_internal_encoding('UTF-8'). Now it all works well. Cron sends the emails perfectly.

OTHER TIPS

May be it is an encoding issue Try this : Open your .csv file in Notepad, Then choose -> Save As..and at the bottom of the "save as" box, there is a select box labelled as "Encoding". Select UTF-8. After selecting UTF-8, Choose select any type under "Save as type" then save the file to a slightly different file name from the original.

You have also to add this line to your php code : header("Content-Type: text/html; charset=UTF-16LE");

Could you tell us what msg error do you get exactly :) how the characters are displayed ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top