473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get Email Message from File

24
<?php $to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";?>

The above is the standard example for a simple email sender.
I have long letters in text and doc formats. Call them letter.txt. or letter.doc
How can I have the computer read the documents into the "$message" line?
The following line does not work.
$message=letter.txt;
How can I get it to work properly?
Or is this just impossible to do?
Sep 18 '06 #1
2 2097
ronverdonk
4,258 Expert 4TB
Use the file_get_contents command, reading the entire file into a string.

[PHP]<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = file_get_contents("file.txt");
$from = "someonelse@example.com";
$headers = "From: $from";
if (mail($to,$subject,$message,$headers))
echo "Mail Sent";
else
echo "Mail message failed";
?>[/PHP]

Info on the command (and error handling) can be found at http://nl2.php.net/manual/en/functio...t-contents.php

Ronald :cool:
Sep 18 '06 #2
jrsjrs
24
Thank you very much ronverdonk!
That was a completely new php command for me.
I spent at least 6 hours trying to solve this problem unsuccessfully.
Incidentally, it works fine with text files, but not with .doc files.
I learn something new every day.
Thanks also to this great website - "thescripts".
Sep 18 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Chuck Anderson | last post by:
Can anyone point me in the right direction? I want to use Php to automate confirmation of someone joining an email list by them replying to an email (so they don't have to have a browser?). I...
3
by: Siv | last post by:
Hi, A little while ago I wrote a small program that allowed the user to view products from a database. The database holds the details of the products which can be viewed via a form and...
0
by: wulongtea | last post by:
I am trying generate an HTML email message with C# Visual Studio 2003 that has a graphics file embedded in the message. (I know i should be using 2005 and the new classes there, but I cannot upgrade...
20
by: Chris Withers | last post by:
Hi All, The following piece of code is giving me issues: from email.Charset import Charset,QP from email.MIMEText import MIMEText charset = Charset('utf-8') charset.body_encoding = QP msg =...
3
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...
7
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and...
4
tolkienarda
by: tolkienarda | last post by:
hi all i have been working for the last several days on a php mailer program that can send newsletters to all of the people in a database it has gone great i can have attachments and other such...
0
by: jibysubhash | last post by:
hi all i have got a php code which sends attachments via mail..... Please help me how to send the file parameters to the php via http service send method.... i am placing the php and flex codes here ...
0
by: tourerukcom | last post by:
Hi i wonder if any one can help. I have script that that sends a email with mulitple attachments. It seems to work fine as i get the email with the attachments on. But other people i send it to...
2
by: Erik Witkop | last post by:
So I have been trying to get this to work all day. I can't get a local file on my web server to attach to an email. Right now I have it printing out in the body of the email. Please help me with...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.