Location: PHPKode > projects > Astmail - Asterisk web voicemail > email_send.php
<?php 
/*

 Copyright (c) 2005-2006 Colorado State Univeristy
 All rights reserved.

Please contact Kyle Haefner hide@address.com
for changes, bug notices or feature requests

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
session_start();
if ($_SESSION[mailbox] =="")
{
header("Location: ./logoff.php");
}

//Include class files
include ("mailbox.class.php");
include ("message.class.php");
include ("folder.class.php");
require("Sajax.php");
//Get info from database
include("config/DBConnection.php"); 
//include config file
include_once ("config/vmail_conf.php");
$sql="select fullname,email from mailboxes where mailbox = '$_SESSION[mailbox]'";
$result = mysql_query($sql,$conn) or die(mysql_error());

//print $sql;

if (mysql_num_rows($result)==1)
{
	$email = mysql_result($result,0,'email');
	$fullname = mysql_result($result,0,'fullname');
}

//get the variables
$message = $_POST[ebody];
$emailsubject = $_POST[subject];
$emailaddress = $_POST[email];

# Is the OS Windows or Mac or Linux
if (strtoupper(substr(PHP_OS,0,3)=='WIN')): $eol="\r\n"; elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')): $eol="\r"; else: $eol="\n"; endif; 


$f_name = $voicemail;
$_SESSION[mailbox]."/".$_GET[folder]."/msg".$_POST[msg].".WAV";
# File for Attachment

$handle=fopen($f_name, 'rb');
$f_contents=fread($handle, filesize($f_name));
$f_contents=chunk_split(base64_encode($f_contents));    //Encode The Data For Transition using base64_encode();
$f_type=filetype($f_name);
fclose($handle);



# Common Headers
$headers .= 'From: '.$fullname.' <'.$emailaddress.'>'.$eol;
$headers .= 'Reply-To: '.$fullname.' <'.$emailaddress.'>'.$eol;
$headers .= 'Return-Path: '.$fullname.' <'.$emailaddress.'>'.$eol;    // these two to set reply address
$headers .= "Message-ID: <".$now.$reply_email.">".$eol;
//$headers .= "X-Mailer: PHP v".phpversion().$eol;          // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";

# Text Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= "This is a multi-part message in MIME format.".$eol;
$msg .= "$message".$eol.$eol;

# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: audio/x-wav; name=\""."msg".$_POST[msg].".WAV"."\"".$eol;  
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\""."msg".$_POST[msg].".WAV"."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
# Setup for text OR html
$msg .= "Content-Type: multipart/alternative".$eol;



/*# HTML Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;*/

# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol;  // finish with two eol's for better security. see Injection.

//print $msg;
# SEND THE EMAIL
//ini_set(sendmail_from,'hide@address.com');  // the INI lines are to force the From Address to be used !
  mail($emailaddress, $emailsubject, $msg, $headers);
//ini_restore(sendmail_from);
header("Location: ./vmail.php?folder=$_GET[folder]&info=Your message has been sent!");
//print "$emailaddress <br> $emailsubject <br> $msg <br> $headers";
?>
Return current item: Astmail - Asterisk web voicemail