473,835 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OUTPUT raw email with php

n8kindt
221 New Member
not sure if anyone can help me with this. i'm using my default email address to pipe to a certain php script. all i want the php script to do is read who the recipients are and send the email to said recipients mostly untouched. i know how to parse the email and read the recipients (that's the easy part). all i need is a way to send out the raw email text (which will be pulled using fopen ) without having to plug it into a function that uses separate parameters for the 'to', 'subject', 'message', etc, etc, fields. essentially, i just want to dump a raw email file into a function and let her fly.

the reason why i want to do this is so i can set up a dynamic email forwarding system. an email addressed to a username in our database is then forwarded to the email address they have specified in their account settings. i have a shared hosting plan (through hostgator) and i'm fairly sure that a method using php is my only option to perform a task such as this. i'm also willing to bet it has something to do with sendmail but i don't have the slightest clue on where to begin.

perhaps also i could figure out how to do this by looking at the inner workings of the mail() function? i haven't figured out where to find that either, however.

any help would be much appreciated!!
thanks - nate
May 12 '09 #1
19 6291
unauthorized
81 New Member
I don't think PHP has the capabilities you are looking for, unless you are willing to phrase the email headers yourself.

Or you could run a local SMTP server on the server machine and use PHP's socket functions to connect to it. This is pretty much how mail() works. You can get all settings from the php.ini file using ini_get() for a zero configuration script.
This is in fact, slightly faster than phrasing data.
May 12 '09 #2
n8kindt
221 New Member
actually, yes the email headers are already constructed. all i want to change is the recipient fields. so how can i use php in this way?

i will also look into what you said about smtp. thanks for the reply

nate
May 12 '09 #3
unauthorized
81 New Member
Expand|Select|Wrap|Line Numbers
  1. $header_beg = strpos($myEmail, "To:") + 3;
  2. $header_end = strpos($myEmail, "\n", $header_beg);
  3.  
  4. substr_replace($myEmail, $myNewAddress, $header_beg, $header_end);
Simple, isn't it? Google next time.
May 12 '09 #4
n8kindt
221 New Member
that is not at all what my question relates to. here's an example. let's say i have a raw email that was read using this php script:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/php -q
  2. <?php
  3. //-q for no output header
  4. // read from stdin 
  5. $fd = fopen("php://stdin", "r"); 
  6. $email = ""; 
  7. while (!feof($fd)) { 
  8. $email .= fread($fd, 1024); 
  9. }
  10.  
  11. ?>
the $email variable would now be a string equal to something like the following:
Expand|Select|Wrap|Line Numbers
  1.  
  2. MIME-Version: 1.0
  3. Received: by 10.142.70.10 with HTTP; Mon, 4 May 2009 14:18:20 -0700 (PDT)
  4. Date: Mon, 4 May 2009 14:18:20 -0700
  5. Delivered-To: erased@gmail.com
  6. Message-ID: <e21c1a870905041418t58e3194atbc1997ef1fd50fd3@mail.gmail.com>
  7. Subject: testing message
  8. From: Nate <erased@gmail.com>
  9. To: recipient@whatever.com
  10. Cc: erased <erased@gmail.com>
  11. Content-Type: multipart/alternative; boundary=001636e0a7e5a0a77304691cb37f
  12.  
  13. --001636e0a7e5a0a77304691cb37f
  14. Content-Type: text/plain; charset=ISO-8859-1
  15. Content-Transfer-Encoding: 7bit
  16.  
  17. testing
  18.  
  19. --001636e0a7e5a0a77304691cb37f
  20. Content-Type: text/html; charset=ISO-8859-1
  21. Content-Transfer-Encoding: 7bit
  22.  
  23. testing
  24.  
  25. --001636e0a7e5a0a77304691cb37f--
  26.  

what i need to do is figure out a way to dump the $email variable into an email process (i would not assume this to be a direct PHP function but i could be wrong) and send it out like as if it were any other regular incoming email being processed. i don't want to touch this raw email other than to edit the recipients and send it on its merry way. as i said earlier, i have no problem parsing the email - i've written scripts to do this many times but i just need a mailman to send out raw email text.
May 12 '09 #5
unauthorized
81 New Member
Looks like I misunderstood your last comment. Like I said, you will need an SMTP server to achieve what you want.

All you need is to open a socket and complete a simple negotiation then.
See the example at http://en.wikipedia.org/wiki/Simple_...communications
If you want more information on the protocol, you will have to dig out RFC5321.
May 12 '09 #6
Markus
6,050 Recognized Expert Expert
Check out some of the good php mail clients (google). I recommend SwiftMailer.
May 12 '09 #7
n8kindt
221 New Member
thanks, markus. i will be looking into that next. thought i would post back with the progress i have made so far. i just found a good class on phpclasses.org that, as far as i can determine, directly connects to smtp from a socket and does send out raw email text. here's the entire project link: http://www.phpclasses.org/browse/package/2958.html but the meat and potatoes of what i need is the socket class which i am attaching to this post. i'll let you know how it goes
Attached Files
File Type: txt sock.txt (3.3 KB, 454 views)
May 12 '09 #8
hoopy
88 New Member
n8kindt,

I know you have solved your question but you seem to making it more difficult for yourself. As Markus said, check out Swift Mailer, it can do exactly what you require which will save you a lot of time.

Its very simple to include in your applications as well.

Best of luck.
May 12 '09 #9
n8kindt
221 New Member
glad you said something. i gave it a closer look and i think you guys are right. no sense in reinventing the wheel. i'll let you know how it goes but i don't anticipate any problems b/c it looks fairly straightforward
May 12 '09 #10

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

Similar topics

16
6999
by: Chuck Amadi | last post by:
Sorry to bovver you again (again) here's script. I still can't see why the get_payload() doesn't produce the plain text message body of an emails in the testwwws users mailbox. As you can see I have tried a few things but no joy what am I missing. Is the another snippet in relation to get_payload to access the body contents print and process to a file. Cheers
5
1814
by: Tushar | last post by:
hello all, i would like to know why this code compiles and gives the output Code 1: ---------- int main(){ printf("String" + 2); }
54
4127
by: bnp | last post by:
Hi, I took a test on C. there was an objective question for program output type. following is the program: main() { char ch; int i =2;
8
14026
by: Yusuf INCEKARA | last post by:
I have a stored procedure : CREATE PROCEDURE STP_GETSTORELIST @RETCUR CURSOR VARYING OUTPUT AS set @RETCUR = CURSOR FORWARD_ONLY STATIC FOR SELECT ID,STORE_NAME FROM T_INF_STORE ORDER BY STORE_NAME OPEN @RETCUR
6
2185
by: Tarren | last post by:
Hi: I have an aspx page that takes a dataset, makes the datagrid, and displays it. The new thing I have to do is take this same output and send it as an email. Is there an easy way to do this? Any examples? Thanks for the help!
32
2811
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input the same file ? If not then how much variation is allowed ? Is it just a bit more or less white space here and there or could could there be larger differences ? If the output is not deterministic then is it possible that the output of the...
3
2390
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central panel. The central panel is intended to display the main content of the cv: when an anchor is selected from the header then the detail is supposed to appear. The javascript is supposed to select the appropriate section 'onclick' and output it....
8
2707
by: Alec MacLean | last post by:
Hi, I'm using the DAAB Ent Lib (Jan 2006) for .NET 2.0, with VS 2005 Pro. My project is a Web app project (using the WAP add in). Background: I'm creating a survey system for our company, for which invites will target selected personnel among our customers via email. Each email will provide a custom hyperlink for each respondent using a SQL generated GUID value in the querystring. The GUID will be checked for validity before the user...
14
1785
by: fdu.xiaojf | last post by:
Hi, I'm writing a program which imports an external module writing in C and calls a function provided by the module to do my job. But the method produces a lot of output to the stdout, and this consumes most of the running time. My question is, is there a way to depress the output produced by the function and hence make my program run faster? It's too complicated for me to modify the source code and recompile the external module.
1
1964
by: laredotornado | last post by:
Hi, I'm using PHP 5. Assuming there are no errors, how do I get the output of an exec call? I'm trying $cmd = 'strings < ' . escapeshellarg($file) . ' | sed - n \'s|.*/Count -\{0,1\}\(\{1,\}\).*|\1|p\' | sort -rn | head -n 1'; exec("$cmd 2>&1", $output, $return); if ($return != 0) {
0
10811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10560
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10233
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9345
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7766
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5804
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.