|
|
|
ส่งเมลล์แบบอัพโหลดไฟล์ไม่ได้ครับ ถ้าส่งแบบตัวอักษรมันไปครับ |
|
|
|
|
|
|
|
ส่งเมลล์แบบอัพโหลดไฟล์ไม่ได้ครับ ไฟล์มันไม่ยอมไปครับ
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>
<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">
<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="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">Send 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("mysql.hostinger.in.th","u561243131_root","12345678") or die("Error Connect to Database");
$objDB = mysql_select_db("u561243131_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">
<tr>
<td></td>
<td><input name="fileAttach" type="file"></td>
</tr>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Send</button>
<button type="reset" class="btn btn-default">Clear</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body></html>
mail.phpCode (PHP)
<html>
<head>
<title>Sending Email</title>
</head>
<body>
<?
$objConnect = mysql_connect("mysql.hostinger.in.th","u561243131_root","12345678") or die("Error Connect to Database");
$objDB = mysql_select_db("u561243131_pig");
$email_sub = $_POST["email_sub"];
$email_mess = $_POST["email_mess"];
$name_room = $_POST["room"];
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";
}
$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>";
@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 = "index3.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]>";
$strSub = $email_sub;
$strVar = $email_mess;
$strMessage = "
<h1>".$strSub."</h1><br>
<div>".$strVar."</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 = "index3.php";</script>';
}
}
?>
</body>
</html>
Tag : PHP, MySQL, HTML/CSS, CakePHP
|
|
|
|
|
|
Date :
2016-07-03 17:08:43 |
By :
itsaret456 |
View :
874 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าแนบไฟล์แนะนำให้ใช้ Library แทนครับ
Code (PHP)
<?php
require_once("mimemail.inc.php");
$mail = new MIMEMAIL("HTML"); // HTML Format
$mail->senderName = "sender name";
$mail->senderMail = "sender@email";
$mail->cc = "cc@email";
$mail->bcc = "bcc@email";
$mail->subject = "This is the subject line";
$mail->body = "Hello! This is a message for you."; // OR: $mail->body = "path_to_file/filename";
$mail->attachment[] = "path_to_file1/filename1";
$mail->attachment[] = "path_to_file2/filename2";
$mail->create();
$mail->send("recipient1@email");
$mail->send("recipient2@email,recipient3@email,recipient4@email");
?>
PHP Mail Class (MIMEMAIL V 1.5)
|
|
|
|
|
Date :
2016-07-04 10:51:50 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|