|
|
|
ช่วยดู code ทีครับผมส่งเมลเป็นไฟล์ไม่ไปครับ มี code ให้ดูครับ |
|
|
|
|
|
|
|
ช่วยดู code ทีครับผมส่งเมลเป็นไฟล์ไม่ไปครับ
emailform.php
Code (PHP)
<html><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="http://pingendo.github.io/pingendo-bootstrap/themes/default/bootstrap.css" rel="stylesheet" type="text/css">
</head><body>
<div class="section">
<div class="container">
<div class="row">
</div>
</div>
<div class="section">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">E-mail</h3>
</div>
<div class="panel-body">
<div class="col-md-12">
<form class="form-horizontal" name="email_form" id="email_form" method="post" action="mail.php" enctype="multipart/form-data">
<div class="form-group">
<div class="col-sm-2">
<label for="inputEmail3" class="control-label">Subject :</label>
</div>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="Add title" name="email_sub" id="email_sub">
</div>
</div>
<div class="form-group">
<div class="col-sm-2">
<label for="inputEmail3" class="control-label">To :</label>
</div>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="Send To" name="sendto" id="sendto">
</div>
</div>
<div class="form-group">
<div class="col-sm-2">
<label for="inputPassword3" class="control-label"></label>
</div>
<div class="col-sm-10">
<textarea rows="15" class="form-control" placeholder="Message" name="email_mess" id="email_mess"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-2">
<label for="inputEmail3" class="control-label">UploadAttach :</label>
</div>
<div class="col-sm-10">
<input name="fileAttach" type="file"><br>
</div>
</div>
<div class="form-group">
<div class="col-sm-2">
<label for="inputEmail3" class="control-label">Room To :</label>
</div>
<div class="col-sm-10">
<SELECT id ="room" name="room" class="form-control ">
<OPTION value="1">Send All</option>
<?php
$objConnect = mysql_connect("localhost","root","12345678") or die("Error Connect to Database");
$objDB = mysql_select_db("pig");
mysql_query("SET NAMES UTF8");
//query all records from the database
$strSQL = "SELECT * FROM room ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery)){
?>
<option value="<?php echo $objResult["name_room"];?>"><?php echo $objResult["name_room"];?></option>
<?php
}
?>
</SELECT>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Send</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body></html>
mail.php
Code (PHP)
<html>
<head>
<title>Sending Email</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","12345678") or die("Error Connect to Database");
$objDB = mysql_select_db("pig");
$email_sub = $_POST["email_sub"];
$sendto = $_POST["sendto"];
$email_mess = $_POST["email_mess"];
$name_room = $_POST["room"];
//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
@mail($strTo,$strSubject,null,$strHeader); // @ = No Show Error //
$all = 1;
if($name_room == $all){
$strSQL = "SELECT * FROM member";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
$strTo = $objResult["email"];
$strSubject = "Alumni-Rmutp News";
$strHeader = "Content-type: text/html; charset=windows-874\n"; // or UTF-8 //
$strHeader .= "From: Admin Alumni-Rmutp<[email protected]>";
$strSub = $email_sub;
$strVar = $email_mess;
$strMessage = "
<h1>".$strSub."</h1><br>
<div>".$strVar."</div>
<div>".$stratt."</div>";
@mail($strTo,$strSubject,$strMessage,$strHeader); // @ = No Show Error //
echo '<script type="text/javascript">alert("send email success");</script>';
echo '<script type="text/javascript">window.location.href = "emailform.php";</script>';
}
}else{
$strSQL = "SELECT * FROM member where room = '$name_room '";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
$strTo = $objResult["email"];
$strSubject = "Alumni-Rmutp News";
$strHeader = "Content-type: text/html; charset=windows-874\n"; // or UTF-8 //
$strHeader .= "From: Admin Alumni-Rmutp<[email protected]>";
$stratt = $fileAttach;
$strSub = $email_sub;
$strVar = $email_mess;
$strMessage = "
<h1>".$strSub."</h1><br>
<div>".$strVar."</div>
<div>".$stratt."</div>";
@mail($strTo,$strSubject,$strMessage,$strHeader); // @ = No Show Error //
echo '<script type="text/javascript">alert("send email success");</script>';
echo '<script type="text/javascript">window.location.href = "emailform.php";</script>';
}
}
?>
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2016-07-13 12:49:26 |
By :
itsaret456 |
View :
810 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ Mail Class ดีกว่าครับ
PHP Sending Mail : ส่งอีเมล์ในรูปแบบต่าง ๆ ด้วย ด้วย PHP
|
|
|
|
|
Date :
2016-07-13 13:36:28 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|