مشکل در PHP self submit form

hamid1357

New Member
سلام به دوستان و اساتید PHP
من یه فرم درخواست self submit درست کردم که وقتی فرم خالی ارسال میشه مشکلی نداره و یه ایمیل برام میاد که جلوی گزینه هاش خالیه ولی اگه گزینه هاش پر بشه بجای یه ایمیل هفت هشت ده تا ایمیل برام میاد . آیا کسی میدونه مشکل از چیه ؟
کد رو هم اینجا میزارم :

کد:
 <?php
$kind = $_POST["kind"];
$name = $_POST["name"];
$company = $_POST["company"];

$addresssent = '[email protected]';
$date = date("d/m/Y H:i:s");
$msg2 = "

      Date: $date

      Name: $name
      
      Subject: $kind
      
      Tel: $company
        
   ";

mail($addresssent,$subject,$msg2);

if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<html>

<head>
<meta http-equiv="Content-Language" content="fa">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>New Page 2</title>
<link rel="stylesheet" type="text/css" href="stylefa.css">
</head>
<body>

<table border="0" width="100%" id="table1" cellspacing="0" cellpadding="0" height="100%" dir="ltr">
	<tr>
		<td align="center" valign="top">

<form method="post" action="<?php echo $PHP_SELF;?>" enctype="utf-8">
<table id="table2" width="501" height="60" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td class="formtd1-left" >
		<select size="1" name="kind" class="formtextbox">
		<option selected>تماس با شرکت</option>
		<option>مشاوره قبل از خرید</option>
		<option>سفارش کالا</option>
		<option>مشاوره بعد از خرید</option>
		<option>مشاوره فنی</option>
		<option>درخواست تعمیرات</option>
		</select></td>
		<td width="2" height="30"></td>
		<td class="formtd1-right" >
		نوع درخواست :</td>
	</tr>
	<tr>
		<td class="formtd2-left" >
		<input type="text" name="name" size="20" class="formtextbox"></td>
		<td width="2" height="30"></td>
		<td class="formtd2-right" >
		نام و نام خانوادگی :</td>
	</tr>
	<tr>
		<td class="formtd1-left" >
		<input type="text" name="company" size="20" class="formtextbox"></td>
		<td width="2" height="30"></td>
		<td class="formtd1-right" >
		شرکت :</td>
	</tr>
	<tr>
		<td class="formtd2-left" >
		<input type="text" name="job" size="20" class="formtextbox"></td>
		<td width="2" height="30"></td>
		<td class="formtd2-right" >
		سمت :</td>
	</tr>
	<tr>
		<td class="formtd1-left" >
		<input type="text" name="tel" size="20" class="formtextbox"></td>
		<td width="2" height="30"></td>
		<td class="formtd1-right" >
		تلفن :</td>
	</tr>
	<tr>
		<td class="formtd2-left" >
		<input type="text" name="fax" size="20" class="formtextbox"></td>
		<td width="2" height="30"></td>
		<td class="formtd2-right" >
		فکس :</td>
	</tr>
	<tr>
		<td class="formtd1-left" >
		<input type="text" name="cell" size="20" class="formtextbox"></td>
		<td width="2" height="30"></td>
		<td class="formtd1-right" >
		تلفن همراه :</td>
	</tr>
	<tr>
		<td class="formtd2-left" >
		<input type="text" name="email" size="20" class="formtextbox"></td>
		<td width="2" height="30"></td>
		<td class="formtd2-right" >
		پست الکترونیکی :</td>
	</tr>
	<tr>
		<td class="formtd1-left" >
		<input type="text" name="address" size="20" class="formtextbox2"></td>
		<td width="2" height="30"></td>
		<td class="formtd1-right" >
		آدرس :</td>
	</tr>
	<tr>
		<td class="formtd2-left" style="height: 160px" >
		<textarea rows="2" name="S1" cols="20" class="formtextbox3"></textarea></td>
		<td width="2" height="30"></td>
		<td class="formtd2-right" style="vertical-align: top" >
		<p style="margin-top: 8px">متن درخواست :</td>
	</tr>
</table>
			<p><input type="submit" value="submit" name="submit"><input type="reset" value="Reset" name="B2"></p>
		</form>

		<p></td>
	</tr>
</table>
<?php
} else {
echo "<br /><br /><br /><br /><center>با تشکر</center><br /><center>درخواست شما دربافت شد.</center><br /><center>کارشناسان ما بزودی با شما تماس خواهند گرفت.</center>";

}
?>
 

ziXet

مدیر انجمن PHP/MYSQL
خب بیشتر از این هم نباید انتظار داشته باشی!

شما باید همه کدهایی که مربوط به ارسال ای-میل هست رو باید تو بلاک else بذاری!

اینجوری وقتی صحه بالا میاد به ایمیل ارسال میشه
 

hamid1357

New Member
دوست عزیز مرسی از پاسخت. ولی من مبتدی هستم اگه ممگنه بیشتر توضیح بدید.
 

ziXet

مدیر انجمن PHP/MYSQL
دوست عزیز مرسی از پاسخت. ولی من مبتدی هستم اگه ممگنه بیشتر توضیح بدید.
خب از اول میگفتی!
درستش کردم برات!
اینو امتحان کن:
PHP:
 <?php
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<html>

<head>
<meta http-equiv="Content-Language" content="fa">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>New Page 2</title>
<link rel="stylesheet" type="text/css" href="stylefa.css">
</head>
<body>

<table border="0" width="100%" id="table1" cellspacing="0" cellpadding="0" height="100%" dir="ltr">
    <tr>
        <td align="center" valign="top">

<form method="post" action="<?php echo $PHP_SELF;?>" enctype="utf-8">
<table id="table2" width="501" height="60" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td class="formtd1-left" >
        <select size="1" name="kind" class="formtextbox">
        <option selected>تماس با شرکت</option>
        <option>مشاوره قبل از خرید</option>
        <option>سفارش کالا</option>
        <option>مشاوره بعد از خرید</option>
        <option>مشاوره فنی</option>
        <option>درخواست تعمیرات</option>
        </select></td>
        <td width="2" height="30"></td>
        <td class="formtd1-right" >
        نوع درخواست :</td>
    </tr>
    <tr>
        <td class="formtd2-left" >
        <input type="text" name="name" size="20" class="formtextbox"></td>
        <td width="2" height="30"></td>
        <td class="formtd2-right" >
        نام و نام خانوادگی :</td>
    </tr>
    <tr>
        <td class="formtd1-left" >
        <input type="text" name="company" size="20" class="formtextbox"></td>
        <td width="2" height="30"></td>
        <td class="formtd1-right" >
        شرکت :</td>
    </tr>
    <tr>
        <td class="formtd2-left" >
        <input type="text" name="job" size="20" class="formtextbox"></td>
        <td width="2" height="30"></td>
        <td class="formtd2-right" >
        سمت :</td>
    </tr>
    <tr>
        <td class="formtd1-left" >
        <input type="text" name="tel" size="20" class="formtextbox"></td>
        <td width="2" height="30"></td>
        <td class="formtd1-right" >
        تلفن :</td>
    </tr>
    <tr>
        <td class="formtd2-left" >
        <input type="text" name="fax" size="20" class="formtextbox"></td>
        <td width="2" height="30"></td>
        <td class="formtd2-right" >
        فکس :</td>
    </tr>
    <tr>
        <td class="formtd1-left" >
        <input type="text" name="cell" size="20" class="formtextbox"></td>
        <td width="2" height="30"></td>
        <td class="formtd1-right" >
        تلفن همراه :</td>
    </tr>
    <tr>
        <td class="formtd2-left" >
        <input type="text" name="email" size="20" class="formtextbox"></td>
        <td width="2" height="30"></td>
        <td class="formtd2-right" >
        پست الکترونیکی :</td>
    </tr>
    <tr>
        <td class="formtd1-left" >
        <input type="text" name="address" size="20" class="formtextbox2"></td>
        <td width="2" height="30"></td>
        <td class="formtd1-right" >
        آدرس :</td>
    </tr>
    <tr>
        <td class="formtd2-left" style="height: 160px" >
        <textarea rows="2" name="S1" cols="20" class="formtextbox3"></textarea></td>
        <td width="2" height="30"></td>
        <td class="formtd2-right" style="vertical-align: top" >
        <p style="margin-top: 8px">متن درخواست :</td>
    </tr>
</table>
            <p><input type="submit" value="submit" name="submit"><input type="reset" value="Reset" name="B2"></p>
        </form>

        <p></td>
    </tr>
</table>
<?php
} else {
$kind = $_POST["kind"];
$name = $_POST["name"];
$company = $_POST["company"];

$addresssent = '[email protected]';
$date = date("d/m/Y H:i:s");
$msg2 = "

      Date: $date

      Name: $name
      
      Subject: $kind
      
      Tel: $company
        
   ";

if(mail($addresssent,$subject,$msg2)){
echo "<br /><br /><br /><br /><center>با تشکر</center><br /><center>درخواست شما دربافت شد.</center><br /><center>کارشناسان ما بزودی با شما تماس خواهند گرفت.</center>";
}
else{ echo "<br /><br /><br /><br /><center>There is something wrong!</center>";}
}
?>
البته باید بگم که خیلی ناشیانی نوشته شده و میتونست بهتر از اینا باشه.

موفق باشید
 

hamid1357

New Member
Shahkey جان مرسی از راهنماییت . همانطور که گفتم من مبتدی ام و ناشی !
مشکلم حل شد.
میخواستم ببینم اگه بخوام این اطلاعات بصورت منظم مثلا در قالب table به ایمیلم ارسال بشه چه تغییراتی باید در کد بدم؟
 

جدیدترین ارسال ها

بالا