View Full Version : فر م فرستادن نظرات کاربران به یک ایمیل معلوم
mohammadi
چهارشنبه 10 خرداد 1385, 10:38 صبح
با سلام به دوستان عزیز
چطور میشه یه فرمی مثل نمونه زیر در سایت گذاشت تا کاربران با زدن کلید submit نظرات خود را به یه ایمیلی که معرفی می کنیم بفرستند
ممنون میشم سریع پاسخ دهید خیلی حیاتی است
nima_jafari
چهارشنبه 10 خرداد 1385, 16:52 عصر
دوست عزیز شما مشکل کدام است:
1- فرم
2- فرستادن email به یک آدرس مشخص.
من یک sample برای مورد دوم برات می گذارم. این کد با C# است.
این فرم برای ارسال یک Email به یک آدرس مشخص است البته دقت داشته باش که mailserver باید به تو اجازه بده.شما با آن می توانید file هم attach کنید.
nima_jafari
چهارشنبه 10 خرداد 1385, 17:09 عصر
این هم sample
nima_jafari
چهارشنبه 10 خرداد 1385, 17:19 عصر
این ظاهرا مشکل داره
================================================== ========
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using NimaGeneralClass1;
namespace AskLibrarian
{
/// <summary>
/// Summary description for SendMessages.
/// </summary>
public class Attachments : System.Web.UI.Page
{
private MailMessage EmailSend=new MailMessage();
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label12;
protected System.Web.UI.WebControls.Button SendBtn;
protected System.Web.UI.HtmlControls.HtmlInputFile File;
protected System.Web.UI.WebControls.Button ConBtn;
protected System.Web.UI.HtmlControls.HtmlInputButton ExitBtn;
protected System.Web.UI.WebControls.Label ErrMsg;
private String GetFileName(String Path)
{
int i=Path.Length-1;
String FileTemp="";
while (Path.Substring(i,1)!="/" && Path.Substring(i,1)!="\\" && i>-1)
FileTemp=Path.Substring(i--, 1)+FileTemp;
return FileTemp;
}
private void SetAttachment()
{
if (System.IO.Directory.Exists(Global.MyDir))
System.IO.Directory.Delete(Global.MyDir,true);
System.IO.Directory.CreateDirectory(Global.MyDir);
String MyFile;
String filename;
if (File.Visible)
{
MyFile=File.PostedFile.FileName;
if (MyFile!="" && Session["MyFile"].ToString()!=MyFile)
{
filename=Global.MyDir+"/"+GetFileName(MyFile);
File.PostedFile.SaveAs(filename);
Session["MyFile"]=filename;
}
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if (Session["UserName"]!=null)
{
try
{
if (Session["SendType"].ToString()=="T")
{
SendBtn.Visible=true;
ExitBtn.Visible=true;
Button2.Visible=false;
ConBtn.Visible=false;
}
else
{
SendBtn.Visible=false;
ExitBtn.Visible=false;
Button2.Visible=true;
ConBtn.Visible=true;
}
}
catch
{
ErrMsg.Text=Global.E_System;
}
}
else
Response.Redirect("ErrorPage.aspx");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ConBtn.Click += new System.EventHandler(this.ConBtn_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.SendBtn.Click += new System.EventHandler(this.SendBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
ErrMsg.Text="";
try
{
SetAttachment();
Response.Redirect("SendMessages.aspx");
}
catch
{
ErrMsg.Text=Global.E_System;
}
}
private void Button2_Click(object sender, System.EventArgs e)
{
try
{
ErrMsg.Text="";
Response.Redirect("SendMessages.aspx");
}
catch
{
ErrMsg.Text=Global.E_System;
}
}
private void SendBtn_Click(object sender, System.EventArgs e)
{
ErrMsg.Text="";
try
{
SetAttachment();
if (Session["MyFile"].ToString()!="")
{
MailAttachment MyAttachment = new MailAttachment(Session["MyFile"].ToString());
EmailSend.Attachments.Add(MyAttachment);
}
EmailSend.From=Session["MainEmail"].ToString().Trim();
EmailSend.To=Session["UserOprEmail1"].ToString().Trim();
EmailSend.Subject="File Sent You From WWW.SRLST.COM";
EmailSend.Body="Hello";
EmailSend.Priority=MailPriority.High;
EmailSend.BodyFormat=MailFormat.Html;
EmailSend.BodyEncoding=System.Text.Encoding.UTF8;
SmtpMail.SmtpServer="mail.srlst.com";
SmtpMail.Send(EmailSend);
Session["MyFile"]="";
}
catch
{
ErrMsg.Text=Global.E_SendEmail;
}
}
private void ConBtn_Click(object sender, System.EventArgs e)
{
ErrMsg.Text="";
try
{
SetAttachment();
Response.Redirect("SendMessages.aspx");
}
catch
{
ErrMsg.Text=Global.E_SendEmail;
}
}
}
}
nima_jafari
چهارشنبه 10 خرداد 1385, 17:21 عصر
قبلی attachment این یکی email
================================================== ========
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using NimaGeneralClass1;
namespace AskLibrarian
{
/// <summary>
/// Summary description for SendMessages.
/// </summary>
public class SendMessages : System.Web.UI.Page
{
private GeneralClass gc=new GeneralClass(Global.Constr);
private ADODB.Recordset RS=new ADODB.Recordset();
private MailMessage EmailSend=new MailMessage();
private String Fldkeyvals;
private String Path1,Path2;
private bool Flag;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.TextBox Subject;
protected System.Web.UI.WebControls.TextBox From;
protected System.Web.UI.WebControls.TextBox Body;
protected System.Web.UI.WebControls.DropDownList UTo;
protected System.Web.UI.WebControls.DropDownList UTotemp;
protected System.Web.UI.WebControls.TextBox To;
protected System.Web.UI.WebControls.Button AttachBtn;
protected System.Web.UI.WebControls.Label FileMsg;
protected System.Web.UI.WebControls.Label ErrMsg;
private void Page_Load(object sender, System.EventArgs e)
{
if (Session["UserName"]!=null)
{
try
{
FileMsg.Text="";
if (Session["MyFile"].ToString()!="")
FileMsg.Text=Global.M_FileMsg;
if (!IsPostBack)
{
if (Session["To"].ToString()!="")
UTo.SelectedIndex=Convert.ToInt16(Session["To"].ToString());
else
UTo.SelectedIndex=0;
Subject.Text=Session["Subject"].ToString();
Body.Text=Session["Body"].ToString();
}
ErrMsg.Text="";
if (Session["UserName"].ToString().StartsWith("OPR") || Session["UserName"].ToString().StartsWith("ADMIN"))
{
Flag=true;
UTo.Visible=true;
AttachBtn.Visible=true;
To.Visible=false;
From.Text=Session["MainEmail"].ToString();
if (UTo.Items.Count==0)
{
Fldkeyvals="username like 'USR%'";
gc.OpenConnection(Global.Constr+Session["UserName"].ToString().Trim());
RS=gc.FindInfoFromDb("T_User_Opr","username,email,name,family,country,fieldstudy,user status,userlock,userprivate",Fldkeyvals,"username");
if (!RS.EOF && RS.Fields["username"].Value.ToString().Trim()!="")
{
RS.MoveFirst();
while (!RS.EOF)
{
UTo.Items.Add(RS.Fields["Email"].Value.ToString().Trim());
UTotemp.Items.Add(RS.Fields["username"].Value.ToString().Trim());
RS.MoveNext();
}
}
gc.CloseConnection();
}
}
else
{
Flag=false;
UTo.Visible=false;
To.Visible=true;
AttachBtn.Visible=false;
From.Text=Session["Email"].ToString();
To.Text=Session["MainEmail"].ToString();
}
}
catch
{
ErrMsg.Text=Global.E_System;
}
}
else
Response.Redirect("ErrorPage.aspx");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.AttachBtn.Click += new System.EventHandler(this.AttachBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
ErrMsg.Text="";
try
{
if (Session["MyFile"].ToString().Trim()!="")
{
MailAttachment MyAttachment = new MailAttachment(Session["MyFile"].ToString());
EmailSend.Attachments.Add(MyAttachment);
Session["MyFile"]="";
}
EmailSend.From=From.Text;
if (Flag)
EmailSend.To=UTo.Items[UTo.SelectedIndex].Text;
else
EmailSend.To=To.Text;
EmailSend.Subject=Subject.Text;
EmailSend.Body=Body.Text;
EmailSend.Priority=MailPriority.High;
EmailSend.BodyFormat=MailFormat.Html;
EmailSend.BodyEncoding=System.Text.Encoding.UTF8;
SmtpMail.SmtpServer="mail.servername.com";
SmtpMail.Send(EmailSend);
try
{
if (Flag)
gc.UpdateInfoInDb("T_User_Opr","emailcount=emailcount+1","username='"+UTotemp.Items[UTo.SelectedIndex].Text+"'");
else
gc.UpdateInfoInDb("T_User_Opr","emailcount=emailcount+1","username='admin'");
if(System.IO.Directory.Exists(Global.MyDir))
System.IO.Directory.Delete(Global.MyDir,true);
Response.Redirect("MainWebPage.aspx");
}
catch
{
ErrMsg.Text=Global.E_System;
}
}
catch
{
ErrMsg.Text=Global.E_SendEmail;
}
}
private void Button2_Click(object sender, System.EventArgs e)
{
try
{
ErrMsg.Text="";
Session["MyFile"]="";
Response.Redirect("MainWebPage.aspx");
}
catch
{
ErrMsg.Text=Global.E_System;
}
}
private void AttachBtn_Click(object sender, System.EventArgs e)
{
try
{
ErrMsg.Text="";
if (Session["UserName"].ToString().ToUpper().StartsWith("USR"))
Session["To"]=To.Text;
else
Session["To"]=UTo.SelectedIndex.ToString();
Session["Subject"]=Subject.Text;
Session["Body"]=Body.Text;
Session["SendType"]="F"; // in session baraye in ast ke vaghti shoma dar "Attachment.aspx" hastid button "edameh" roshan bashad ya "ersal"
Response.Redirect("Attachments.aspx");
}
catch
{
ErrMsg.Text=Global.E_System;
}
}
}
}
nima_jafari
چهارشنبه 10 خرداد 1385, 17:22 عصر
اینم html مربوط به attachment
================================================== =======
<%@ Page language="c#" Codebehind="Attachments.aspx.cs" AutoEventWireup="false" Inherits="AskLibrarian.Attachments" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML dir="rtl">
<HEAD>
<title></title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="javascript">
function Closeform(){
close();
}
</script>
</HEAD>
<body bgColor="#ffffcc" background="Image\BGround.jpg" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:button id="ConBtn" style="Z-INDEX: 102; LEFT: 288px; POSITION: absolute; TOP: 168px" tabIndex="7"
runat="server" Height="24px" Width="97px" ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma"
Font-Bold="True" Text="ادامه"></asp:button><asp:button id="Button2" style="Z-INDEX: 103; LEFT: 184px; POSITION: absolute; TOP: 168px" tabIndex="8"
runat="server" Height="24px" Width="97px" ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True" Text="بازگشت"></asp:button><asp:label id="Label12" style="Z-INDEX: 101; LEFT: 408px; POSITION: absolute; TOP: 144px" runat="server"
Width="30px" ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True"> فایل:</asp:label><asp:label id="ErrMsg" style="Z-INDEX: 105; LEFT: 136px; POSITION: absolute; TOP: 192px" runat="server"
Width="300px" ForeColor="Red" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True"></asp:label>
<INPUT id="File" dir="rtl" style="Z-INDEX: 104; LEFT: 128px; WIDTH: 273px; POSITION: absolute; TOP: 141px; HEIGHT: 22px; BACKGROUND-COLOR: azure"
tabIndex="2" type="file" size="26" runat="server">
<asp:Button id="SendBtn" style="Z-INDEX: 100; LEFT: 288px; POSITION: absolute; TOP: 168px" tabIndex="7"
runat="server" Height="24px" Width="97px" ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma"
Font-Bold="True" Text="ارسال"></asp:Button><INPUT style="FONT-WEIGHT: bold; FONT-SIZE: small; Z-INDEX: 108; LEFT: 184px; WIDTH: 97px; POSITION: absolute; TOP: 168px; HEIGHT: 24px"
type="button" value="خروج" onclick="Closeform()" id="ExitBtn" name="ExitBtn" runat="server"></form>
</body>
</HTML>
nima_jafari
چهارشنبه 10 خرداد 1385, 17:23 عصر
اینم html مربوط به email
================================================== =======
<%@ Page language="c#" Codebehind="SendMessages.aspx.cs" AutoEventWireup="false" Inherits="AskLibrarian.SendMessages" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML dir="rtl">
<HEAD>
<title></title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body bgColor="#ffffcc" background="Image\BGround.jpg" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="Label1" style="Z-INDEX: 101; LEFT: 496px; POSITION: absolute; TOP: 0px" runat="server"
ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True" Width="11px">از:</asp:label><asp:textbox id="Body" style="Z-INDEX: 107; LEFT: 11px; POSITION: absolute; TOP: 96px" tabIndex="6"
runat="server" ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True" Width="481px" BackColor="Azure" Height="200px" TextMode="MultiLine"></asp:textbox><asp:textbox id="Subject" style="Z-INDEX: 106; LEFT: 11px; POSITION: absolute; TOP: 72px" tabIndex="5"
runat="server" ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True" Width="481px" BackColor="Azure"></asp:textbox><asp:textbox id="From" style="Z-INDEX: 105; LEFT: 192px; POSITION: absolute; TOP: 0px" runat="server"
ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True" Width="300px" BackColor="Azure" ReadOnly="True"></asp:textbox><asp:label id="Label4" style="Z-INDEX: 104; LEFT: 496px; POSITION: absolute; TOP: 104px" runat="server"
ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True" Width="20px">پیغام:</asp:label><asp:label id="Label3" style="Z-INDEX: 103; LEFT: 496px; POSITION: absolute; TOP: 72px" runat="server"
ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True" Width="40px">موضوع:</asp:label><asp:label id="Label2" style="Z-INDEX: 102; LEFT: 496px; POSITION: absolute; TOP: 24px" runat="server"
ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True" Width="14px">به:</asp:label><asp:button id="Button1" style="Z-INDEX: 108; LEFT: 328px; POSITION: absolute; TOP: 304px" tabIndex="7"
runat="server" ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True" Width="103" Height="24px" Text="ارسال"></asp:button><asp:button id="Button2" style="Z-INDEX: 109; LEFT: 224px; POSITION: absolute; TOP: 304px" tabIndex="8"
runat="server" ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True" Width="103" Height="24px" Text="بازگشت"></asp:button>
<asp:textbox id="To" style="Z-INDEX: 110; LEFT: 192px; POSITION: absolute; TOP: 24px" runat="server"
ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True" Width="300px"
BackColor="Azure" ReadOnly="True"></asp:textbox><asp:dropdownlist id="UTo" style="Z-INDEX: 111; LEFT: 192px; POSITION: absolute; TOP: 24px" tabIndex="1"
runat="server" Font-Bold="True" Width="300px" BackColor="Azure"></asp:dropdownlist><asp:dropdownlist id="UTotemp" style="Z-INDEX: 112; LEFT: 11px; POSITION: absolute; TOP: 0px" tabIndex="1"
runat="server" Width="145px" BackColor="Azure" Visible="False"></asp:dropdownlist><asp:label id="ErrMsg" style="Z-INDEX: 113; LEFT: 120px; POSITION: absolute; TOP: 328px" runat="server"
ForeColor="Red" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True" Width="300px"></asp:label><INPUT style="FONT-WEIGHT: bold; FONT-SIZE: xx-small; Z-INDEX: 114; LEFT: 120px; WIDTH: 103px; FONT-FAMILY: Tahoma; POSITION: absolute; TOP: 304px; HEIGHT: 24px"
onclick="javascript:open('Sendmessage.Htm','Help','WIDTH=55 0,HEIGHT=350')" type="button" value="راهنما">
<asp:button id="AttachBtn" style="Z-INDEX: 115; LEFT: 392px; POSITION: absolute; TOP: 48px"
tabIndex="7" runat="server" ForeColor="Black" Font-Size="Smaller" Font-Names="Tahoma" Font-Bold="True"
Width="100px" Height="24px" Text="درخواست فایل"></asp:button><asp:label id="FileMsg" style="Z-INDEX: 116; LEFT: 192px; POSITION: absolute; TOP: 52px" runat="server"
ForeColor="Blue" Font-Size="X-Small" Font-Names="Tahoma" Font-Bold="True" Width="193px" Height="16px"></asp:label></form>
</body>
</HTML>
nima_jafari
چهارشنبه 10 خرداد 1385, 17:24 عصر
دوست عزیز می خواستم zipfile را برات بفرستم ولی خطا داد
امیدوارم بدردت بخورد.
متشکرم
tabib_m
چهارشنبه 10 خرداد 1385, 18:53 عصر
این همه کد؟؟؟؟!!!!!!!
بابا یه کد php بنویس خودتو راحت کن ، توی انجمن php نمونه ش هست ، یه سرچ کوچولو کافیه.
nima_jafari
پنج شنبه 11 خرداد 1385, 19:21 عصر
طبیب جان کل یک برنامه تحت C# , HTML است که فقط باید اجراش کنی.می دونم یک کد کوچک داره.
این کد هم email می فرستد و هم file می فرستد.
patoo87
جمعه 16 تیر 1385, 01:07 صبح
بابا طبیب راست میگه
mail(to,subject,content,headers);
تموم
فایلم با پی اچ پی بفرستی راحت تری
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.