Update of /cvsroot/php-blog/serendipity/include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31718/include
Modified Files:
functions.inc.php functions_comments.inc.php
Log Message:
Create serendipity_sendMail() which makes it a lot easier to send mail :)
It also supports mb_send_mail() so we can send mails with multibyte chars
Index: functions_comments.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/functions_comments.inc.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- functions_comments.inc.php 3 Dec 2004 10:07:39 -0000 1.9
+++ functions_comments.inc.php 28 Dec 2004 17:49:44 -0000 1.10
@@ -359,7 +359,7 @@
global $serendipity;
$entryURI = serendipity_archiveURL($entry_id, $title, 'baseURL');
- $subject = '[' . $serendipity['blogTitle'] . '] ' . sprintf(NEW_COMMENT_TO_SUBSCRIBED_ENTRY, $title);
+ $subject = sprintf(NEW_COMMENT_TO_SUBSCRIBED_ENTRY, $title);
$pgsql_insert = '';
$mysql_insert = '';
@@ -405,7 +405,7 @@
);
}
- mail($subscriber['email'], $subject, $text . $serendipity['signature'], "From: {$serendipity['blogTitle']} <$fromEmail>\r\n". $serendipity['mailheaders']);
+ serendipity_sendMail($subscriber['email'], $subject, $text, $fromEmail);
}
}
@@ -435,7 +435,7 @@
if ($type == 'TRACKBACK') {
/******************* TRACKBACKS *******************/
- $subject = '[' . $serendipity['blogTitle'] . '] ' . NEW_TRACKBACK_TO . ' ' . $title;
+ $subject = NEW_TRACKBACK_TO . ' ' . $title;
$text = sprintf(A_NEW_TRACKBACK_BLAHBLAH, $title)
. "\n"
. "\n" . REQUIRES_REVIEW . ': ' . (($moderate_comment) ? YES : NO) . (isset($serendipity['moderate_reason']) ? ' (' . $serendipity['moderate_reason'] . ')' : '')
@@ -456,7 +456,7 @@
} else {
/******************* COMMENTS *********************/
- $subject = '[' . $serendipity['blogTitle'] . '] ' . NEW_COMMENT_TO . ' ' . $title;
+ $subject = NEW_COMMENT_TO . ' ' . $title;
$text = sprintf(A_NEW_COMMENT_BLAHBLAH, $serendipity['blogTitle'], $title)
. "\n" . LINK_TO_ENTRY . ': ' . $entryURI
. "\n"
@@ -477,5 +477,5 @@
. (($moderate_comment) ? "\n" . str_repeat(' ', 3) . str_pad(APPROVE_COMMENT, 15) . ' -- '. $approveURI : '');
}
- return mail($to, $subject, $text . $serendipity['signature'], "From: {$serendipity['blogTitle']} - $fromName <$to>". (!empty($fromEmail) ? "\r\nReply-To: $fromEmail" : ''). "\r\n". $serendipity['mailheaders']);
+ return serendipity_sendMail($to, $subject, $text, $fromEmail);
}
Index: functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/functions.inc.php,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- functions.inc.php 22 Dec 2004 17:44:52 -0000 1.13
+++ functions.inc.php 28 Dec 2004 17:49:44 -0000 1.14
@@ -149,9 +149,39 @@
return serendipity_db_query($querystring);
}
-/**
-* Creates a filename that consists of [a-zA-z0-9-] (with some custom adjustments (space -> _, ä -> ae and such)
-**/
+
+function serendipity_sendMail($to, $subject, $message, $fromMail, $headers = NULL, $fromName = NULL) {
+ global $serendipity;
+
+ if ( !is_null($headers) && !is_array($headers) ) {
+ trigger_error(__FUNCTION__ . ': $headers must be either an array or null', E_USER_ERROR);
+ }
+
+ if ( is_null($fromName) ) {
+ $fromName = $serendipity['blogTitle'];
+ }
+
+ /* Prefix all mail with weblog title */
+ $subject = '['. $serendipity['blogTitle'] . '] '. $subject;
+
+ /* Append signature to every mail */
+ $message .= "\n" . sprintf(SIGNATURE, $serendipity['blogTitle']);
+
+ /* Always add these headers */
+ $headers[] = 'X-Mailer: Serendipity/'. $serendipity['version'];
+ $headers[] = 'X-Engine: PHP/'. phpversion();
+ $headers[] = 'Content-Type: text/plain; charset=' . LANG_CHARSET;
+ $headers[] = 'From: '. $fromName .' <'. $fromMail .'>';
+
+ if ( function_exists('mb_send_mail') ) {
+ $funcSend = 'mb_send_mail';
+ } else {
+ $funcSend = 'mail';
+ }
+
+ return $funcSend($to, $subject, $message, implode("\n", $headers));
+}
+
function serendipity_makeFilename($str) {
static $from = array(
' ',
|