Hi guys.
I'm a total PHP newbie and would really appreciate some help with this.
I would like to edit the code shown below which sends an email so that the user can add a file attachment. The user needs to be able to browse and select this from their c drive. The attachment does not need to be saved after it has been sent.
Preferably users would also be restricted to only using .doc and .pdf format attachments.
OK, here's the code.
Thanks very much.
1. CONTACT.PHP
--------------------------------------------
2. CONTACT.TPL
I'm a total PHP newbie and would really appreciate some help with this.
I would like to edit the code shown below which sends an email so that the user can add a file attachment. The user needs to be able to browse and select this from their c drive. The attachment does not need to be saved after it has been sent.
Preferably users would also be restricted to only using .doc and .pdf format attachments.
OK, here's the code.
Thanks very much.
1. CONTACT.PHP
Code:
<?
session_start();
include_once("admin/inc.php");
$tplContact=new TplLoad;
$tplContact->assign("phpself",$_SERVER['PHP_SELF']);
if ($set_contact_login_need)
check_valid_user("");
// Refereer information
$legal = 0;
$lServerRef = explode("/",getenv("HTTP_REFERER"));
$lUserid=getParam("user_id","");
$tplContact->assign("ad_owner",getParam("ad_owner",""));
$tplContact->assign("id",getParam("id",""));
$tplContact->assign("user_id",getParam("user_id",""));
if ($set_img_validation==1)
$tplContact->assign("image_validation",1);
if (getParam("submit",""))
{
$errorStr="";
$tplContact->assign("contact_name",getParam("contact_name",""));
$tplContact->assign("contact_email",getParam("contact_email",""));
$tplContact->assign("contact_message",strip_tags(getParam("contact_message","")));
if (empty($lUserid))
$errorStr.="<li>".LA_ERROR_MSG5."</li>";
if (!validEmail(getParam("contact_email","")))
$errorStr.="<li>".LA_ERROR_MSG21."</li>";
if (getParam("contact_email","")=="")
$errorStr.="<li>".LA_ERROR_MSG8."</li>";
if (getParam("contact_name","")=="")
$errorStr.="<li>".LA_ERROR_MSG5."</li>";
if (!empty($set_ref) && !eregi("$set_ref",".$lServerRef[2]."))
$errorStr.="<li>".LA_REF_FAILED."</li>";
if (getParam("contact_message","")=="")
$errorStr.="<li>".LA_ERROR_MSG88."</li>";
if ($_SESSION["validate_sign_session"] <> $_REQUEST["validate_sign"] && $set_img_validation)
$errorStr.="<li>".LA_IMG_VER_FAILED."</li>";
if (empty($errorStr))
{
$sql = "select ad_owner,user_name,user_email from $ads_tbl,$usr_tbl where ad_owner=user_id AND user_id = $lUserid limit 1";
$sql_resultads = q($sql);
$row=mysql_fetch_array($sql_resultads);
$lRecieveEmail = $row["user_email"];
$lRecieveName = $row["user_name"];
$lContactMessage=strip_tags(getParam("contact_message",""));
$lContactName=strip_tags(getParam("contact_name",""));
$lContactEmail=strip_tags(getParam("contact_email",""));
$sql="select ad_title,ad_id from $ads_tbl where ad_id='".getParam("id","")."'";
$res_title=q($sql);
$row_title=mysql_fetch_array($res_title);
$lAdTitle=$row_title["ad_title"];
$lAdID=$row_title["ad_id"];
$lEmailBody=formatString(LA_EMAIL_BODY,array(getParam("ad_owner",""),"$lContactName","$lContactMessage","$lContactEmail",getRemoteIp(),"$lAdTitle","$lAdID","$name_of_site","$url"));
$lEmailTitle=formatString(LA_EMAIL,array(getParam("ad_owner",""),"$lContactName","$lContactMessage","$lContactEmail",getRemoteIp(),"$lAdTitle","$lAdID","$name_of_site","$url"));
$tplContact->assign("message_sent",formatString(LA_SENT_MESSAGE,array("$lRecieveName")));
sendEmail($lRecieveEmail,$lContactEmail,$lEmailTitle,$lEmailBody);
$tplContact->assign("contact_ok",1);
$sql_2 = "update $usr_tbl set user_contacted = user_contacted + 1 where user_id = $lUserid";
$sql_resultupd = q ($sql_2);
addToHistory(2,$lUserid,"","");
}
else
{
$tplContact->assign("contact_fail",$errorStr);
}
}
else
{
$sql_eier = "select user_name from $usr_tbl where user_id = $lUserid";
$result = q ($sql_eier);
$row_contact = mysql_fetch_array($result);
$tplContact->assign("ad_owner",$row_contact["user_name"]);
$tplContact->assign("contact_name",$_SESSION["user_name"]);
$tplContact->assign("contact_email", $_SESSION["user_email"]);
}
$tplContact->display("contact.tpl");
?>
--------------------------------------------
2. CONTACT.TPL
Code:
<table class="box"><tr><th>{$smarty.const.LA_KONTAKT}</th></tr><td>
<h2>{$smarty.const.LA_KONTAKT}</h2>
{if $contact_ok}
{$message_sent}
{else}
<form method="post" action="{$phpself}" name="itemForm" id="itemForm">
<input type="hidden" name="ad_owner" value="{$ad_owner}">
<input type="hidden" name="user_id" value="{$user_id}">
<input type="hidden" name="id" value="{$id}">
<input type="hidden" name="contact" value="1">
<!-- t1 -->
{$smarty.const.LA_MAIN_MESSAGE} <b>{$ad_owner}</b>.<br />
{if $contact_fail}
<ol class="red"> {$contact_fail} </ol>
{/if}
<!-- t3 -->
<table border="0" cellspacing="1">
<tr>
<td width="50%" valign="top"> {$smarty.const.ADD_USER_NAME} </td>
<td width="50%" valign="top"> <input type="text" name="contact_name" value="{$contact_name}" size="35" > </td>
</tr>
<tr>
<td width="50%" valign="top"> {$smarty.const.ADD_USER_EMAIL} </td>
<td width="50%" valign="top"> <input type="text" name="contact_email" value="{$contact_email}" size="35" > </td>
</tr>
<tr>
<td width="50%" valign="top"> {$smarty.const.LA_CONTACT_MSG} </td>
<td width="50%" valign="top"><textarea rows="5" name="contact_message" cols="27" rows="10">{$contact_message}</textarea></td>
</tr>
{if $image_validation}
<tr>
<td> {$smarty.const.LA_IMG_VER}:</td>
<td valign="top" class="star"><img src="val_img.php" alt="" /></td></tr>
<tr>
<td> {$smarty.const.LA_IMG_VER2}:</td>
<td valign="top" class="star">
<input type="text" class="txt" name="validate_sign" size="16" maxlength="16" /> *</td></tr>
{/if}
</table>
<input type="submit" value="{$smarty.const.LA_KONTAKT}" name="submit" class="button" />
</form>
{/if}
<p> </p>
</td></tr></table>
{literal}
<script language="javascript" type="text/javascript">
<!--
content=document.getElementById("contact_name");
if( content != null ){content.focus();}
-->
</script>
{/literal}