 |
|
|
 |
 |
|
<?php # Is the OS Windows or Mac or Linux
if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {
$eol="\r\n";
} elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) {
$eol="\r";
} else {
$eol="\n";
} ?>
<?php
$letter = "Test.pdf";
# File for Attachment
$f_name="c:/".$letter; // use relative path OR ELSE big headaches. $letter is my file for attaching.
$handle=fopen($f_name, 'rb');
$f_contents=fread($handle, filesize($f_name));
$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
$f_type=filetype($f_name);
fclose($handle);
# To Email Address
$emailaddress="To@xxxx";
# Message Subject
$emailsubject="Heres An Email with a PDF".date("Y/m/d H:i:s");
# Message Body
ob_start();
//require("emailbody.php"); // i made a simple & pretty page for showing in the email
$body=ob_get_contents(); ob_end_clean();
# Common Headers
$headers .= 'From: Me <From@xxxx>'.$eol;
$headers .= 'Reply-To: Me <From@xxxx>'.$eol;
$headers .= 'Return-Path: Me <From@xxxx>'.$eol; // these two to set reply address
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: application/pdf; name=\"".$letter."\"".$eol; // sometimes i have to send MS Word, use 'msword' instead of 'pdf'
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$letter."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
# Setup for text OR html
$msg .= "Content-Type: multipart/alternative".$eol;
# Text Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= "This is a multi-part message in MIME format.".$eol;
$msg .= "If you are reading this, please update your email-reading-software.".$eol;
$msg .= "+ + Text Only Email from Genius Jon + +".$eol.$eol;
# HTML Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;
# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
# SEND THE EMAIL
ini_set(sendmail_from,'[email protected]'); // the INI lines are to force the From Address to be used !
mail(, $emailsubject, $msg, $headers);
ini_restore(sendmail_from);
?>
ลองแล้วใช้ได้นะครับ
(อ้างอิงจาก http://www.thaiadmin.org/board/index.php?action=printpage%3Btopic=38855.0)
|
 |
 |
 |
 |
Date :
2009-05-10 10:49:18 |
By :
intelman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือผมเพิ่งเข้ามาเรียนรู้ภาษา phpครับและตอนนี้ผมกำลังเขียนเวปแต่ตอนนี้ผมกำลังเจอปัญหาอยู่ที่ว่า
การล็อกอินของผม ที่ต้องการให้ผู้เข้าชมเวปไซด์กรอกข้อความดังนี้
ชื่อ,สกุล
เบอร์โทร
อีเมลล์
และหลังบ้านที่ผมเข้าไปดูสมาชิกที่ล็อกกอินเข้ามา สามารถเห็นดังนี้
ลำดับที่ วันที่ ชื่อ,สกุล เบอร์โทร อีเมลล์ ลบ
1 5/5/52 นาย น่ารัก ชมดี 0871234567 [email protected] delete
2 6/5/52 นาย ฃื่นชม งามตา 0897894561 [email protected] delete
ผมต้องทำอย่างไรครับ ช่วยแนะนำสเตบบายสเตบถ้าไม่รบกวนจนเกินไปครับ
คือผมเขียน ฟอร์มจาก php แต่ผมไม่รู้ว่าต้องส่งอย่างไรเพื่อให้เข้าสู่ฐานข้อมูล จึงขอรบกวนว่าผมต้องติดตั้งโปรแกรมอะไรใน databaseของผม
และผมต้องมี ซ้อตโค๊ตอะไรเป็นตัวส่งเพื่อสามารถจะดูได้ครับ
หากไม่เป็นการรบกวนมากไปขอความกรุณาช่วยหนูน้อยที่เพิ่งหัดเดินคนนี้ด้วยครับ ขอบคุณมากครับ
|
 |
 |
 |
 |
Date :
2009-05-18 23:31:34 |
By :
kangpla |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (phpSendMailUploadAttach.html)
<html>
<head>
<title>ThaiCreate.Com PHP Sending Email</title>
</head>
<body>
<form action="phpSendMailUploadAttach.php" method="post" enctype="multipart/form-data" name="frmMain">
<table width="343" border="1">
<tr>
<td>To</td>
<td><input name="txtTo" type="text" ></td>
</tr>
<tr>
<td>Subject</td>
<td><input name="txtSubject" type="text"></td>
</tr>
<tr>
<td>Description</td>
<td><textarea name="txtDescription" cols="30" rows="4"></textarea></td>
</tr>
<tr>
<td>Form Name</td>
<td><input name="txtFormName" type="text"></td>
</tr>
<tr>
<tr>
<td>Form Email</td>
<td><input name="txtFormEmail" type="text"></td>
</tr>
<tr>
<td>Attachment</td>
<td><input name="fileAttach" type="file"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Send"></td>
</tr>
</table>
<br>
<br>
<br>
</form>
</body>
</html>
Code (phpSendMailUploadAttach.php)
<html>
<head>
<title>ThaiCreate.Com PHP Sending Email</title>
</head>
<body>
<?
$strTo = $_POST["txtTo"];
$strSubject = $_POST["txtSubject"];
$strMessage = nl2br($_POST["txtDescription"]);
//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));
$strHeader = "";
$strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=windows-874\n"; // or UTF-8 //
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
//*** 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";
}
$flgSend = @mail($strTo,$strSubject,null,$strHeader); // @ = No Show Error //
if($flgSend)
{
echo "Email Sending.";
}
else
{
echo "Email Can Not Send.";
}
?>
</body>
</html>
Ref : PHP Sending Email Upload Form & Attachment Files
|
 |
 |
 |
 |
Date :
2009-05-19 06:19:01 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือนกต้องการทำแบบฟอร์มการส่งเมลืที่สามารถเลือกอีเมลืมาจากตารางในฐานข้อมูลและสามารถส่งได้หลาย ๆ เมล์พร้อมกันจะทำอย่างไรคะ ช่วยทีนะคะขอบคุณผู้รู้ทุกท่านที่จะกรุณาสละเวลาค่ะ
|
 |
 |
 |
 |
Date :
2010-03-15 08:54:02 |
By :
nok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|