Hi, Chechu!
Try my own script i wrote for my administrationpanel,
Create a .lib file called, "messenger.lib", add paste following code:
PHP Code:
<?php
class messenger
{
var $data = array(), $headers = array();
var $prio;
var $txt_plain;
var $password = "";
var $notification = "";
/*
*
* Function: messenger()
* Added: Jan 28, 2007 - 08:47 by mbrodin
* Last edited: Apr 30, 2007 - 14:30 by mbrodin
*
* @ Gobal function
*
*/
function messenger()
{
}
function prepare_file( $file, $txt = true )
{
$this->useFile = $file;
if( !$this->fileCached[$file] )
{
$this->txt_plain = ( $txt ? true : false );
$txtf = ( !$txt ? "_html" : "" );
$mailFile = $file . ".txt";
if( !file_exists( $mailFile ) )
{
die("<p>File " . $mailFile . " doesn't exists!</p>");
}
$this->fileCached[$file] = $mailFile;
}
}
function setHeaders($HData, $value)
{
if( !empty($value) )
{
if( !is_array( $value ) )
{
$this->headers[] = $HData . ": " . $value;
}
elseif( is_array( $value ) )
{
$this->headers[] = $HData . ": " . implode(", ", $value);
}
}
}
function setSubject( $subject )
{
$this->data['SUBJECT'] = trim($subject);
}
function setFrom( $email, $name = "" )
{
$this->data['FROM']['email'] = trim($email);
$this->data['FROM']['name'] = trim($name);
}
function setTo( $email, $name = "" )
{
$this->data['TO']['email'] = trim($email);
$this->data['TO']['name'] = trim($name);
}
function setCC( $email, $name = "" )
{
$pos = ( isset($this->data['CC']) ? sizeof($this->data['CC']) : 0 );
$this->data['CC'][$pos]['email'] = trim($email);
$this->data['CC'][$pos]['name'] = trim($name);
}
function setBCC( $email, $name = "" )
{
$pos = ( isset($this->data['BCC']) ? sizeof($this->data['BCC']) : 0 );
$this->data['BCC'][$pos]['email'] = trim($email);
$this->data['BCC'][$pos]['name'] = trim($name);
}
function replyTo( $email, $name = "" )
{
$this->data['REPLY_TO'] = trim($email);
}
function setPrio( $prio = 2 )
{
$this->prio = $prio;
}
function setNotification($email, $name = "")
{
$this->notification = ( $name != "" ? $name . " <" . $email . ">" : $email );
}
function setAttachment( $attachment )
{
$pos = ( isset($this->data['ATTACHMENT']) ? sizeof($this->data['ATTACHMENT']) : 0 );
$this->data['ATTACHMENT'][$pos]['file'] = trim($file);
$this->data['ATTACHMENT'][$pos]['type'] = trim($type);
}
function setUserInfo( $data = array() )
{
$pos = ( isset($this->data["USER"]) ? sizeof($this->data["USER"]) : 0 );
foreach( $data As $type => $value )
{
$this->data["USER"][$pos][$type] = $value;
}
}
function execute($mailtype = "email")
{
$tpl_file = $this->getFile($this->fileCached[$this->useFile]);
$cc = array();
// Is CC set or not?
foreach( $this->data['CC'] As $type => $value )
{
$cc[] = ( $value['name'] != "" ? $value['name'] . " <" . $value['email'] . ">" : $value['email'] );
}
$bcc = array();
// Is BCC set or not?
foreach( $this->data['BCC'] As $type => $value )
{
$bcc[] = ( $value['name'] != "" ? $value['name'] . " <" . $value['email'] . ">" : $value['email'] );
}
$http_host = str_replace(array("www."), array(""), $_SERVER["HTTP_HOST"] );
switch( $this->prio )
{
case 1:
$prio = 1;
$prio_txt = "High";
break;
case 5:
$prio = 5;
$prio_txt = "Low";
break;
default:
$prio = 3;
$prio_txt = "Normal";
break;
}
$from = ( ( $this->data['FROM']['name'] != "" ) && ( $this->data['FROM']['email'] != "" ) ? $this->data['FROM']['name'] . " <" . $this->data['FROM']['email'] . ">" : $this->data['FROM']['name'] . " <noreply@" . $http_host . ">" );
// ----------------------------------
// Start set Headers ...
// ----------------------------------
$this->setHeaders("From", $from );
// If CC
if( is_array($cc) )
{
$this->setHeaders("Cc", $cc);
}
// If Bcc
if( is_array($bcc) )
{
$this->setHeaders("Bcc", $bcc);
}
if( $this->data['REPLY_TO'] )
{
$this->setHeaders("Reply-To", $this->data['REPLY_TO']);
}
$this->setHeaders("Return-Path:", $from);
$this->setHeaders("MIME-Version", "1.0");
$this->setHeaders("Message-ID", "<" . time() . "@" . $http_host . ">");
$this->setHeaders("Date", gmdate('D, d M Y H:i:s T', time() ) );
$this->setHeaders("Content-Type", "text/" . ( $this->txt_plain ? "plain" : "html" ) . "; charset=UTF-8");
$this->setHeaders("Content-Transfer-Encoding", "7bit");
if( $this->notification != "" )
{
$this->setHeaders("Disposition-Notification-To", $this->notification);
}
$this->setHeaders("X-Priority", $prio);
$this->setHeaders("X-MSMail-Priority", $prio_txt );
$this->setHeaders("X-Mailer", "PHP 5x");
$this->setHeaders("X-MimeOLE", "PHP 5x");
$tpl_file = preg_replace("/\{(.*?)\}/", "", $tpl_file);
switch( $mailtype )
{
case 'email':
if( mail($this->data['TO']['name'] . " <" . $this->data['TO']['email'] . ">", $this->data['SUBJECT'], $tpl_file, implode("\r\n", $this->headers) ) )
{
return TRUE;
}
return FALSE;
break;
}
}
function getFile($file)
{
if( ( $tpl_file = file_get_contents( $file ) ) === false )
{
die("Can't get contents from <em>" . $file . "</em>.");
}
return $this->addStuff($tpl_file);
}
function addStuff($txt)
{
$txt = trim($txt);
foreach( $this->data["USER"] As $type )
{
foreach( $type As $name => $value )
{
$txt = str_replace("{" . $name . "}", $value, $txt);
}
}
return $txt;
}
}
?>
Create a txt-file and call it "message.txt" and paste following code:
PHP Code:
Dit is een automatisch verzonden email. Gelieve hierop niet te antwoorden.
Beste {NAME},
Bedankt voor je bericht aan hetbestevoordeel.be
We zullen je zo snel mogelijk beantwoorden.
Dit was je bericht:
{MESSAGE}
and last, create the file, "sendmail.php" and paste:
PHP Code:
<?php
if( $_POST["action"] == "send" )
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
include("messenger.lib");
$messenger = new messenger();
// Set this to your own name and email-address ...
$messenger->setFrom("info@cecicasariego.com", "Admin");
$messenger->setBCC("jurgen.schepers@euphonynet.be", "Jurgen");
$messenger->setBCC("info@cecicasariego.com", "Admin");
// Set priority: 1 = High, 3 = Normal, 5 = Low
$messenger->setPrio(1);
// Set the subject ...
$messenger->setSubject("Je bericht aan hetbestevoordeel.be");
// The user information
$messenger->setUserInfo( array(
"NAME" => $name,
"MESSAGE" => $message,
"DATE" => date("M d, Y H:i.s", time())
) );
// To who is it?
$messenger->setTo($email, $name);
// Find the template you will use and send away ...
$messenger->prepare_file( "message", true);
if( $messenger->execute("email") )
{
echo '<p align="center"><font color="#003366">Je bericht is goed verzonden<br>en je zult een bevestiging ontvangen.<br>We beantwoorden je zo snel mogelijk.</font></p>';
}
else
{
echo '<p align="center"><font color="#FF0000">Gelieve alle gegevens in te vullen!</font></p><p><a href="contact.html">[terug]</a>';
}
}
else
{
echo '<p>You must send it from a form!</p>';
}
?>
This is very usefull and very very powerfull script when you will send away email with PHP!
PS! Make sure those files are in thesame directory!!
Hopes this code was usefull for U,
.
Best regards,
mbrodin
Bookmarks