Skip to content

Commit db13d3c

Browse files
committed
fixed mail subjet encoding
1 parent e810f97 commit db13d3c

File tree

1 file changed

+96
-96
lines changed

1 file changed

+96
-96
lines changed

batch/sendNewsletter.php

Lines changed: 96 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,96 @@
1-
<?php
2-
// ini_set('max_execution_time', 60);
3-
$return_code = 0;
4-
$_NO_TOKEN = true;
5-
$_NO_USER_NEEDED = true;
6-
require_once '../includes/main.inc.php';
7-
require_once dirname(__FILE__) . '/../libs/PHPMailer/class.phpmailer.php';
8-
9-
$targetsQuery =
10-
'Select * FROM (Select Nom, Prenom, Email, id, lastLog, lastLetter, IF(lastLog IS NULL AND lastLetter IS NULL, NULL, IF(lastLetter IS NULL, lastLog, IF(lastLog IS NULL, lastLetter, IF(lastLog > lastLetter, lastLog, lastLetter)))) as last FROM ( SELECT personnes.id, Nom, Prenom, Max(DateLog) as lastLog, Max(sentDate) As lastLetter, personnes.Email FROM `personnes` Left Join stats_logs On (personnes.id = stats_logs.personnes_id) Left Join newsletters On (personnes.id = newsletters.personnes_id) WHERE personnes.DateMort IS NULL AND outOfFamily = 0 AND personnes.Email is not null GROUP BY personnes.id) lastEvents ) t2 WHERE last IS NULL OR last < DATE_SUB(NOW(), INTERVAL 7 DAY) order by last asc limit 5';
11-
12-
$targets = Context::getInstance()->getSql()->fetchAll($targetsQuery, array());
13-
14-
echo 'Nombre de lettres a envoyer : ' . sizeof($targets) . "";
15-
foreach ($targets As $t) {
16-
$failure = false;
17-
echo 'Target : ' . $t['Prenom'] . ' ' . $t['Nom'] . ' : ' . ($t['last'] === null ? 'jamais' : $t['last']) . ' (' . $t['Email'] . ')' . "<br/>";
18-
19-
$newsletters_id = Context::getInstance()->getDb()->newsletters()->insert(array(
20-
'personnes_id' => $t['id'], 'email' => $t['Email']
21-
));
22-
23-
echo 'Newsletter generated : "' . $newsletters_id . '"<br/>';
24-
25-
$newsletter = Context::getInstance()->getDb()->newsletters[$newsletters_id];
26-
27-
//Create a new PHPMailer instance
28-
$mail = new PHPMailer();
29-
$mail->CharSet = 'UTF-8';
30-
//Set who the message is to be sent from
31-
$mail->SetFrom(Config::get('SENDER_ADRESS', 'MAIL'), Config::get('SENDER_NAME', 'MAIL'));
32-
33-
//Set who the message is to be sent to
34-
if (Config::get('BCC_ADRESS', 'MAIL') !== false) {
35-
$mail->AddBCC(Config::get('BCC_ADRESS', 'MAIL'), 'WebMaster');
36-
}
37-
38-
if (Config::get('TEST_ADRESS', 'MAIL') !== false) {
39-
$mail->AddAddress(Config::get('TEST_ADRESS', 'MAIL'), $t['Prenom'] . ' ' . $t['Nom']);
40-
} else {
41-
$mail->AddAddress($t['Email'], $t['Prenom'] . ' ' . $t['Nom']);
42-
}
43-
44-
//Set the subject line
45-
$mail->Subject = 'L\'actualité du site'/* . ' (' . $t['Email'] . ')'*/;
46-
47-
$images = array();
48-
$content = getNewsAfter($t['last'], $t, $images, $newsletters_id);
49-
50-
foreach ($images As $id => $hash) {
51-
if (Context::getInstance()->getDb()->newsletters_images()
52-
->insert(array(
53-
'hash' => $hash, 'photos_id' => $id, 'newsletters_id' => $newsletters_id
54-
)) == false) {
55-
echo 'Fail to update images for newsletter<br/>';
56-
$failure = true;
57-
break;
58-
}
59-
}
60-
if ($failure === true) {
61-
continue;
62-
}
63-
64-
$newsletter['content'] = $content;
65-
if ($newsletter->update() == false) {
66-
echo 'Fail to update newsletter for content<br/>';
67-
$failure = true;
68-
continue;
69-
}
70-
71-
//Read an HTML message body from an external file, convert referenced images to embedded, convert HTML into a basic plain-text alternative body
72-
$mail->MsgHTML($content);
73-
74-
//Send the message, check for errors
75-
if (Config::get('SEND', 'MAIL') === false || $mail->Send() === false) {
76-
echo 'Mailer Error for ' . $t['Prenom'] . ' ' . $t['Nom'] . ' - "' . $t['Email'] . '" : ' . $mail->ErrorInfo . "<br/>";
77-
$newsletter['error'] = $mail->ErrorInfo;
78-
} else {
79-
echo "Message sent to " . $t['Email'] . "<br/>";
80-
$newsletter['sentDate'] = Db_Sql::getNowString();
81-
if ($newsletter->update() == false) {
82-
echo 'Fail to update newsletter for sending<br/>';
83-
}
84-
}
85-
}
86-
87-
function getNewsAfter($date, $personne, &$images, $newsletters_id) {
88-
$context = Context::getInstance();
89-
ob_start();
90-
91-
include dirname(__FILE__) . '/../includes/newsletter/news.inc.php';
92-
93-
return ob_get_clean();
94-
}
95-
96-
exit($return_code);
1+
<?php
2+
// ini_set('max_execution_time', 60);
3+
$return_code = 0;
4+
$_NO_TOKEN = true;
5+
$_NO_USER_NEEDED = true;
6+
require_once '../includes/main.inc.php';
7+
require_once dirname(__FILE__) . '/../libs/PHPMailer/class.phpmailer.php';
8+
9+
$targetsQuery =
10+
'Select * FROM (Select Nom, Prenom, Email, id, lastLog, lastLetter, IF(lastLog IS NULL AND lastLetter IS NULL, NULL, IF(lastLetter IS NULL, lastLog, IF(lastLog IS NULL, lastLetter, IF(lastLog > lastLetter, lastLog, lastLetter)))) as last FROM ( SELECT personnes.id, Nom, Prenom, Max(DateLog) as lastLog, Max(sentDate) As lastLetter, personnes.Email FROM `personnes` Left Join stats_logs On (personnes.id = stats_logs.personnes_id) Left Join newsletters On (personnes.id = newsletters.personnes_id) WHERE personnes.DateMort IS NULL AND outOfFamily = 0 AND personnes.Email is not null GROUP BY personnes.id) lastEvents ) t2 WHERE last IS NULL OR last < DATE_SUB(NOW(), INTERVAL 7 DAY) order by last asc limit 5';
11+
12+
$targets = Context::getInstance()->getSql()->fetchAll($targetsQuery, array());
13+
14+
echo 'Nombre de lettres a envoyer : ' . sizeof($targets) . "";
15+
foreach ($targets As $t) {
16+
$failure = false;
17+
echo 'Target : ' . $t['Prenom'] . ' ' . $t['Nom'] . ' : ' . ($t['last'] === null ? 'jamais' : $t['last']) . ' (' . $t['Email'] . ')' . "<br/>";
18+
19+
$newsletters_id = Context::getInstance()->getDb()->newsletters()->insert(array(
20+
'personnes_id' => $t['id'], 'email' => $t['Email']
21+
));
22+
23+
echo 'Newsletter generated : "' . $newsletters_id . '"<br/>';
24+
25+
$newsletter = Context::getInstance()->getDb()->newsletters[$newsletters_id];
26+
27+
//Create a new PHPMailer instance
28+
$mail = new PHPMailer();
29+
$mail->CharSet = 'UTF-8';
30+
//Set who the message is to be sent from
31+
$mail->SetFrom(Config::get('SENDER_ADRESS', 'MAIL'), Config::get('SENDER_NAME', 'MAIL'));
32+
33+
//Set who the message is to be sent to
34+
if (Config::get('BCC_ADRESS', 'MAIL') !== false) {
35+
$mail->AddBCC(Config::get('BCC_ADRESS', 'MAIL'), 'WebMaster');
36+
}
37+
38+
if (Config::get('TEST_ADRESS', 'MAIL') !== false) {
39+
$mail->AddAddress(Config::get('TEST_ADRESS', 'MAIL'), $t['Prenom'] . ' ' . $t['Nom']);
40+
} else {
41+
$mail->AddAddress($t['Email'], $t['Prenom'] . ' ' . $t['Nom']);
42+
}
43+
44+
//Set the subject line
45+
$mail->Subject = 'L\'actualité du site'/* . ' (' . $t['Email'] . ')'*/;
46+
47+
$images = array();
48+
$content = getNewsAfter($t['last'], $t, $images, $newsletters_id);
49+
50+
foreach ($images As $id => $hash) {
51+
if (Context::getInstance()->getDb()->newsletters_images()
52+
->insert(array(
53+
'hash' => $hash, 'photos_id' => $id, 'newsletters_id' => $newsletters_id
54+
)) == false) {
55+
echo 'Fail to update images for newsletter<br/>';
56+
$failure = true;
57+
break;
58+
}
59+
}
60+
if ($failure === true) {
61+
continue;
62+
}
63+
64+
$newsletter['content'] = $content;
65+
if ($newsletter->update() == false) {
66+
echo 'Fail to update newsletter for content<br/>';
67+
$failure = true;
68+
continue;
69+
}
70+
71+
//Read an HTML message body from an external file, convert referenced images to embedded, convert HTML into a basic plain-text alternative body
72+
$mail->MsgHTML($content);
73+
74+
//Send the message, check for errors
75+
if (Config::get('SEND', 'MAIL') === false || $mail->Send() === false) {
76+
echo 'Mailer Error for ' . $t['Prenom'] . ' ' . $t['Nom'] . ' - "' . $t['Email'] . '" : ' . $mail->ErrorInfo . "<br/>";
77+
$newsletter['error'] = $mail->ErrorInfo;
78+
} else {
79+
echo "Message sent to " . $t['Email'] . "<br/>";
80+
$newsletter['sentDate'] = Db_Sql::getNowString();
81+
if ($newsletter->update() == false) {
82+
echo 'Fail to update newsletter for sending<br/>';
83+
}
84+
}
85+
}
86+
87+
function getNewsAfter($date, $personne, &$images, $newsletters_id) {
88+
$context = Context::getInstance();
89+
ob_start();
90+
91+
include dirname(__FILE__) . '/../includes/newsletter/news.inc.php';
92+
93+
return ob_get_clean();
94+
}
95+
96+
exit($return_code);

0 commit comments

Comments
 (0)