Skip to content
Snippets Groups Projects
Commit 8504d02b authored by Hannes Riebl's avatar Hannes Riebl
Browse files

Improve mail function

git-svn-id: https://textgridlab.org/svn/textgrid/trunk/middleware/tgauth@13765 7c539038-3410-0410-b1ec-0f2a7bf1c452
parent 7440f167
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ include 'webinit.inc.php'; ...@@ -5,7 +5,7 @@ include 'webinit.inc.php';
if($_POST['mail']){ if($_POST['mail']){
$mail = $_POST['mail']; $mail = $_POST['mail'];
$imap->mail($mail['reciever'], $mail['subject'], $mail['body'], true); $imap->mail($mail['reciever'], $mail['subject'], $mail['body']);
$status='Mail an '.$mail['reciever'].' wurde versendet'; $status='Mail an '.$mail['reciever'].' wurde versendet';
} }
......
...@@ -4,69 +4,77 @@ require_once('Mail.php'); ...@@ -4,69 +4,77 @@ require_once('Mail.php');
require_once('Mail/mime.php'); require_once('Mail/mime.php');
class tgImap { class tgImap {
var $conf;
var $sender;
var $bcc;
var $reply;
var $conf; function __construct($conf) {
var $sender; $this->conf = $conf;
var $cc; $this->bcc = $conf['mail']['bcc'];
var $reply; $this->reply = $conf['mail']['reply'];
$this->sender = $conf['mail']['sender'];
function __construct( $conf) { // $params['debug'] = true;
$this->conf = $conf; $params['host'] = $conf['mail']['smtpHost'];
$this->sender = $conf['mail']['sender']; $params['localhost'] = $conf['mail']['smtpEhlo'];
$this->cc = $conf['mail']['cc']; $params['username'] = $conf['mail']['smtpUser'];
$this->reply = $conf['mail']['reply'];
$params['host'] = $conf['mail']['smtpHost']; $this->smtp =& Mail::factory('smtp', $params);
$params['username'] = $conf['mail']['smtpUser']; }
//$params['debug'] = true;
$params['localhost'] = $conf['mail']['smtpEhlo'];
$this->smtp =& Mail::factory('smtp', $params);
}
function mail($to, $subject, $body, $cc=false) {
/*
// Falls eine Zeile der Nachricht mehr als 70 Zeichen enthälten könnte,
// sollte wordwrap() benutzt werden (http://de.php.net/manual/de/function.mail.php)
$body = wordwrap($body, 70);
$header = 'From: '. $this->sender . "\n" .
'Reply-To: '. $this->sender . "\n" .
'Cc: ' . $this->cc . "\n" .
'X-Mailer: PHP/' . phpversion() . "\n" .
'MIME-Version: 1.0' . "\n" .
'Content-type: text/plain; charset=UTF-8' . "\n".
'Content-Transfer-Encoding: 8bit' . "\n";
// replace linebreaks on www.textgrid.de function mail($to, $subject, $body) {
$body = str_replace("\r\n", "\n", $body); /**
* Falls eine Zeile der Nachricht mehr als 70 Zeichen enthälten könnte,
mail($to, $subject, $body, $header);*/ * sollte wordwrap() benutzt werden (http://de.php.net/manual/de/function.mail.php):
*
$text = $body; * $body = wordwrap($body, 70);
$html = '<html><body>'.nl2br($body).'</body></html>'; * $header = 'From: '. $this->sender . "\n" .
$crlf = "\n"; * 'Reply-To: '. $this->sender . "\n" .
* 'Cc: ' . $this->cc . "\n" .
* 'X-Mailer: PHP/' . phpversion() . "\n" .
* 'MIME-Version: 1.0' . "\n" .
* 'Content-type: text/plain; charset=UTF-8' . "\n".
* 'Content-Transfer-Encoding: 8bit' . "\n";
*
* Replace line breaks on www.textgrid.de:
*
* $body = str_replace("\r\n", "\n", $body);
* mail($to, $subject, $body, $header);
*/
$mime = new Mail_mime(array('eol' => $crlf, 'html_charset' => 'UTF-8', 'text-charset' => 'UTF-8')); $recipients = $to . ', ' . $this->bcc;
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$headers['From'] = $this->sender; $headers['Bcc'] = $this->bcc;
$headers['To'] = $to; $headers['From'] = $this->sender;
$headers['Reply-To'] = $this->reply; $headers['Reply-To'] = $this->reply;
$headers['Subject'] = $subject; $headers['Subject'] = $subject;
$headers['To'] = $to;
if($cc) {
$headers['Cc:'] = $this->cc; $body = wordwrap($body, 70);
} $text = $body;
// $html = '<html><body>' . nl2br($body) . '</body></html>';
$body = $mime->get();
$headers = $mime->headers($headers);
$this->smtp->send($to, $headers, $body);
} $mime = new Mail_mime(array('eol' => "\n",
'head_charset' => 'UTF-8',
'text_charset' => 'UTF-8',
'text_encoding' => '8bit')
);
// $mime = new Mail_mime(array('eol' => "\n",
// 'head_charset' => 'UTF-8',
// 'html_charset' => 'UTF-8',
// 'text_charset' => 'UTF-8',
// 'text_encoding' => '8bit')
// );
$mime->setTXTBody($text);
// $mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
$this->smtp->send($recipients, $headers, $body);
}
} }
?> ?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment