PHP - adjuntar archivo en email

   
Vista:

adjuntar archivo en email

Publicado por mdroca (3 intervenciones) el 28/02/2008 15:47:04
Me gustaria añadir la opcion de adjuntar un archivo en un formulario de una aplicación CMS. Os dejo el código por si alguien me pudiese echar una mano, os doy las gracias por adelantado.

<?php

if (!defined("_LOAD_PAGE_")) {
die("<table style='padding: 2px; border: 1px solid #999; background-color: #EEE; font-family: Verdana; font-size: 10px;' align='center'><tr><td><b>Error:</b> This file cannot be opened directly!</td></tr></table>");
}

$op = isset($_POST['op']) ? inCode($_POST['op']) : "" ;
$name = isset($_POST['name']) ? trim(inCode($_POST['name'])) : "" ;
$email = isset($_POST['email']) ? inCode($_POST['email']) : "" ;
$argument = isset($_POST['argument']) ? inCode($_POST['argument']) : "" ;
$subject = isset($_POST['subject']) ? trim(inCode($_POST['subject'])) : "" ;
$message = isset($_POST['message']) ? inCode($_POST['message']) : "" ;

$pagerow = $dblink->get_row("SELECT fullscreen FROM memht_pagine WHERE nome='$page'");
$fullScreen = intval($pagerow['fullscreen']);

require_once("inc/inc_header.php");
if (isset($_GET['page'])) { page_title($page); }
openTable();
switch($op) {
case "send":
sendMail($name,$email,$argument,$subject,$message);
break;
default:
contForm();
break;
}
closeTable();
require_once("inc/inc_footer.php");

function contForm() {
global $dblink,$siteConfig,$visitorInfo,$user;

?>
<form name="contact" id="contact" method="post" action="index.php?page=contact">
<table align="center">
<?php
if (isUser($user)) {
$row = $dblink->get_row("SELECT email FROM memht_utenti WHERE user='$user'");
$email = outCode($row['email']);
} else {
$user = "";
$email = "";
}
echo "<tr><td align='right'><b>"._NAME_."</b></td><td><input type='text' name='name' size=30 value="$user"></td></tr> ";
echo "<tr><td align='right'><b>"._EMAIL_."</b></td><td><input type='text' name='email' size=40 value="$email"></td></tr> ";
?>
<tr><td align="right"><b><?php echo _ARGUMENT_; ?></b></td>
<td><select name="argument">
<option value="<?php echo _GENERALINFO_; ?>"><?php echo _GENERALINFO_; ?></option>
<option value="<?php echo _PROBSITE_; ?>"><?php echo _PROBSITE_; ?></option>
<option value="<?php echo _COMMERCIAL_; ?>"><?php echo _COMMERCIAL_; ?></option>
<option value="<?php echo _PROGRAMMING_; ?>"><?php echo _PROGRAMMING_; ?></option>
<option value="<?php echo _PERSONAL_; ?>"><?php echo _PERSONAL_; ?></option>
<option value="<?php echo _OTHER_; ?>"><?php echo _OTHER_; ?></option>
</select></td></tr>
<tr><td align="right"><b><?php echo _OBJECT_; ?></b></td><td><input type="text" name="subject" size=40></td></tr>
<tr>
<td align="right" valign="top"><b><?php echo _MESSAGE_; ?></b></td>
<td><textarea name="message" cols=30 rows=5 wrap=virtual></textarea></td>
</tr>
<tr><td align="right" valign="top"> </td><td> </td></tr>
<tr><td align="right"><b><?php echo _DATE_; ?></b></td><td><?php echo @date(Y.".".m.".".d)."-".@date(H.".".i); ?></td></tr>
<tr><td align="right"><b><?php echo _IP_; ?></b></td><td><?php echo $visitorInfo['ip']; ?></td></tr>
<?php
if (extension_loaded('gd') AND $siteConfig['graphic_check']==1) {
echo "<tr><td></td><td><img src='".$siteConfig['site_url']."/imgCode.php?name=chk_contact&nc=".md5(time()+rand())."' align='absbottom' title='header=["._SECURITY_CODE_."] body=["._SECURITY_CODE_TEXT_."]'></td></tr> ";
echo "<tr><td align='right'><b>"._CODE_."</b></td><td><input type='text' name='post_code_page' size='8' maxlength='255'></td></tr> ";
}
?>
<input type="hidden" name="op" value="send">
<input type="hidden" name="ok" value=true>
<tr><td colspan="2"><center><input type="submit" name="submit" value="<?php echo _SEND_; ?>"> <input type="reset" name="Submit" value="<?php echo _DELETE_; ?>"></center></td></tr>
</table>
</form>
<?php
}

function sendMail($name,$email,$argument,$subject,$message) {
global $siteConfig,$visitorInfo;

@session_start();
if ((isset($_POST['post_code_page']) AND isset($_SESSION['chk_contact']) AND strtolower($_POST['post_code_page'])==strtolower($_SESSION['chk_contact'])) OR !(extension_loaded('gd') AND $siteConfig['graphic_check']==1)) {

$send = true;
if ($name=="" OR !validate($name)) { $send = false; $msg = "<b>"._FIELDINVALID_."</b>: "._NAME_; }
if (!validEmail($email)) { $send = false; $msg = "<b>"._FIELDINVALID_."</b>: "._EMAIL_; }
if ($subject=="" OR !validate($subject)) { $send = false; $msg = "<b>"._FIELDINVALID_."</b>: "._OBJECT_; }
if ($message=="") { $send = false; $msg = "<b>"._EMPTY_."</b>: "._MESSAGE_; }

if ($send) {
$subject = $siteConfig['site_name'];
$msg = "$subject ";

$msg .= _NAME_.": $name ";
$msg .= _EMAIL_.": $email ";
$msg .= _ARGUMENT_.": $argument ";
$msg .= _OBJECT_.": $subject ";
$msg .= _MESSAGE_.": $message ";
$msg .= _DATE_.": ".@date(Y.".".m.".".d)."-".@date(H.".".i)." ";
$msg .= _IP_.": ".$visitorInfo['ip']." ";

$mailheaders = "From: $name <$email> ";
$mailheaders .= "Reply-To: $email ";

@mail($siteConfig['webmaster_mail'], $subject, $msg, $mailheaders);
echo "<center><b>"._MAILSENT_."</b><br>";
echo "<center>"._THANKFORCONTACT_."</center>";
} else {
echo "<div align='center' id='errorText'>$msg</div>";
}
} else {
echo "<div align='center' id='errorText'><b>"._WRONGSECCODE_."</b></div>";
}
}

?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder