Hi
I am already send a mail using Php with some attachement into it. My Problem is the attachement file is in my Database(mysql). I don't know how can i get from database and then add to my mail. -
<?php function send_mail($emailaddress, $fromaddress, $emailsubject, $body, $ccaddress, $attachments=false) {
-
$eol="\r\n";
-
$mime_boundary=md5(time()); # Common Headers
-
$headers .= 'From: Sangeetha<'.$fromaddress.'>'.$eol;
-
$headers .= 'Cc: <'.$ccaddress.'>'.$eol;
-
$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
-
$headers .= 'MIME-Version: 1.0'.$eol;
-
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
-
$msg = "";
-
if ($attachments !== false) {
-
for($i=0; $i < count($attachments); $i++) {
-
if (is_file($attachments[$i]["file"])) { # File for Attachment
-
$file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1));
-
$handle=fopen($attachments[$i]["file"], 'rb');
-
$f_contents=fread($handle, filesize($attachments[$i]["file"])); $f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
-
fclose($handle); # Attachment
-
$msg .= "--".$mime_boundary.$eol;
-
$msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol;
-
$msg .= "Content-Transfer-Encoding: base64".$eol;
-
$msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$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 .= strip_tags(str_replace("<br>", "\n", $body)).$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,$fromaddress); // the INI lines are to force the From Address to be used !
-
mail($emailaddress, $emailsubject, $msg, $headers); ini_restore(sendmail_from);
-
echo "mail send"; }
-
$emailaddress = "xxx@xx.com";
-
$fromaddress = "yyy@yahoo.com";
-
$ccaddress = "zzz@yahoo.com";
-
$emailsubject = "Test"; $link = mysql_connect("myConnection") or die ("Error connecting to mysql:"); mysql_select_db("index",$link) or die("Unable to select database: . mysql_error()");
-
//$commid = $_POST["CommId"];
-
$selectSql = "select CommId, Attachment from COMM_EML_ATTACHMENT where CommId = 4167"; $
-
result = mysql_query($selectSql,$link);
-
while($row = mysql_fetch_array($result)) {
-
$commid = $row["CommId"]; # Use relative paths to the attachments $attachments = Array( Array("file"=> $row["Attachment"],"content_type"=>"application/msword"));
-
-
# Message Body $body="This is a test message! ";
-
-
$result = send_mail($emailaddress, $fromaddress, $emailsubject, $body, $ccaddress, $attachments); }
-
mysql_close($link); ?>
please help to solve it
Thanks
Chitu.
1 2398
Heya, Chitu03. Welcome to TSDN!
You can retrieve your file from the database the same way you would retrieve any other data. MySQL and PHP simply treat the file as a really long binary string.
[EDIT: Ah. I see that the framework you are using requires a file path. Try using file_put_contents() to create a temporary file.]
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jammer |
last post by:
Can someone give me some sample code to use CDONTS.new to send email
with an attachment?
I've got sample code from the following website;
...
|
by: Robbie De Sutter |
last post by:
Hello,
How do I open a new, empty e-mail message from the default e-mail client
whereby the sender is given and a file is attached?
Currently I use the command (vb.net):
---...
|
by: m_evergreen |
last post by:
Errors:
An unhandled exception of type 'System.Web.HttpException' occurred in
system.web.dll
Additional information: Could not access 'CDO.Message' object.
innerexception is "Exception has...
|
by: Mike Charney |
last post by:
Is there a simple way to send SMTP email from Access VBA?
Mike
m charney at dunlap hospital dot org
|
by: Cimento Cola |
last post by:
Hello all.
Hope anyone can help me!
I have this form, with:
Please choose your file: (browse)
The main purpose is the user to select a local file and then when he submits
a mail should be...
|
by: =?Utf-8?B?SHVnaA==?= |
last post by:
Hi There,
I use follow code to send email inside VB.NET 2005. It does not work well.
Error message of "Failure sending email" would occue. However, email was
sent out sometimes. I am confused...
|
by: maxxxxel |
last post by:
Hi
Can anyone help me with some asp code , I changed the code to use CDO.message instead of the old cdont.sys to send mail from a ASP webpage which works fine.
Our problem is that when we send...
|
by: sxwend |
last post by:
I am trying to use the following post results (http://www.thescripts.com/forum/thread189759.html) and add another requirement. I need to send the results to just the email addresses that the query...
|
by: deepaks85 |
last post by:
Dear All,
I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |