j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 rubing, all I'm doing is sending text in the email. nothing else... =/ I have no experience with PEAR though. Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 so I've figured out the From and Subject not showing up issue but the email message is not going through ... ??? this is what i have. #!/usr/bin/php -q <?php ini_set('error_reporting',E_ALL); $db_host = "asd"; $db_user = "asd"; $db_pwd = "asd"; $db_name = "asd"; $db_table = "users"; $db_emailfield = "email"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $sql = "SELECT `$db_emailfield` FROM `$db_table`;"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ $emails = $row['email']; $ChangeTo = 'noreply@asd.com'; $ForwardTo = $emails; // Read the pipe $open_file = fopen("php://stdin","r"); $email = ""; while (!feof($open_file)) { $email .= fread($open_file,1024); } fclose ($open_file); // Take info from emai; $lines = explode("\n",$email); $from = "noreply@123.com"; $subject = "123"; $message = ""; $to = $ForwardTo; $splittingheaders = true; for ($i=0;$i<count($lines);$i++) { if ($splittingheaders) { if (preg_match("/^From: (.*)/",$lines[$i],$matches)) { if (strpos($lines[$i],"<")) { // The name is before the email $data = explode ("<",$lines[$i]); $from = substr(trim($data[1]),0,-1); } else { $from = $matches[1]; } } if (preg_match("/^Subject: (.*)/",$lines[$i],$matches)) { $subject = $matches[1]; } } else { $message .= $lines[$i]."\n"; } if (trim($lines[$i]=="")) { $splittingheaders = false; } } $message = <<< EOF $message EOF; $headers = "Content-type: text/html\n"; $headers .= "From: $from\n"; $headers .= "Return-Path: $from\n"; //$headers .= "To: $to\n"; mail ($ForwardTo,$subject,$message,$headers); } ?> Quote Link to comment Share on other sites More sharing options...
rubing Posted June 3, 2008 Share Posted June 3, 2008 so...you ARE receiving the message, but it's empty? what is the content of $lines[$i], $message? Why don't you make a non-executable version of this script, so you can visit it as a web page and then try echoing these variables. And then post them. Also, send it to a yahoo account that won't filter it out as junk. Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 Ok so this is what I need the script to do... an email is sent with data in the body to a certain email every day at a certain time. When that email is sent it should pipe it to the script and the script should auto pull the emails from a db I made using mysql and forward that email on to the list. I'm still a noobie in php so thanks for baring with me. Quote Link to comment Share on other sites More sharing options...
rubing Posted June 3, 2008 Share Posted June 3, 2008 So then shouldn't $message =$email Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 3, 2008 Author Share Posted June 3, 2008 So then shouldn't $message =$email I've tried that too.... Quote Link to comment Share on other sites More sharing options...
rubing Posted June 3, 2008 Share Posted June 3, 2008 Can you send any message?? Like what if you just say: $message ="Here is a test message"; Also is $email a string? Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 4, 2008 Author Share Posted June 4, 2008 ok i've tested $message = "testing msg"; and it sends the msg through. The following part of the script: $splittingheaders = true; for ($i=0;$i<count($lines);$i++) { if ($splittingheaders) { if (preg_match("/^From: (.*)/",$lines[$i],$matches)) { if (strpos($lines[$i],"<")) { // The name is before the email $data = explode ("<",$lines[$i]); $from = substr(trim($data[1]),0,-1); } else { $from = $matches[1]; } } if (preg_match("/^Subject: (.*)/",$lines[$i],$matches)) { $subject = $matches[1]; } } else { $message .= $lines[$i]."\n"; } if (trim($lines[$i]=="")) { $splittingheaders = false; } } $message = <<< EOF $message EOF; $headers = "Content-type: text/html\n"; $headers .= "From: $from\n"; $headers .= "Return-Path: $from\n"; //$headers .= "To: $to\n"; I don't understand at all... ??? Quote Link to comment Share on other sites More sharing options...
rubing Posted June 4, 2008 Share Posted June 4, 2008 this part of your script is parsing the $lines array by REGEX for the subject, from, and message contents. I am not sure why the following is an if-else statement (the latter part should assign the message contents to $message and be mandatory): if (preg_match("/^Subject: (.*)/",$lines[$i],$matches)) { $subject = $matches[1]; } } else { $message .= $lines[$i]."\n"; } Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 4, 2008 Author Share Posted June 4, 2008 any other ideas that my be wrong with the script? I'm soooo close to finishing this project up! Quote Link to comment Share on other sites More sharing options...
rubing Posted June 4, 2008 Share Posted June 4, 2008 what happens if you replace $message with $email ? mail ($ForwardTo,$subject,$message,$headers); Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 4, 2008 Author Share Posted June 4, 2008 I've tried that too... have any other ideas? Quote Link to comment Share on other sites More sharing options...
rubing Posted June 4, 2008 Share Posted June 4, 2008 Well...first try something like this, to make sure you can read an email in to standard input and then re-send it. (sorry the code key is not working) #!/usr/bin/php -q <?php ini_set('error_reporting',E_ALL); $db_host = "asd"; $db_user = "asd"; $db_pwd = "asd"; $db_name = "asd"; $db_table = "users"; $db_emailfield = "email"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $sql = "SELECT `$db_emailfield` FROM `$db_table`;"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ $emails = $row['email']; $ChangeTo = 'noreply@asd.com'; $ForwardTo = $emails; // Read the pipe $open_file = fopen("php://stdin","r"); $email = ""; while (!feof($open_file)) { $email .= fread($open_file,1024); } fclose ($open_file); $ForwardTo='wherever@yahoo.com '; $subject='whatever'; $headers='your headers'; mail ($ForwardTo,$subject,$email,$headers); ?> Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 4, 2008 Author Share Posted June 4, 2008 I'm getting the same results here... no luck! = / Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 4, 2008 Author Share Posted June 4, 2008 I will offer $15 by paypal whoever can solve this issue for me.... Quote Link to comment Share on other sites More sharing options...
discomatt Posted June 4, 2008 Share Posted June 4, 2008 Freelancer's forum Hopefully their price agrees with yours. Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 4, 2008 Author Share Posted June 4, 2008 ok so now I have stripped it down and followed the direction here at http://www.evolt.org/article/Incoming_Mail_and_PHP/18/27914/index.html Here is the code that I am using now: #!/usr/bin/php <?php // read from stdin $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); // handle email $lines = explode("\n", $email); // empty vars $from = ""; $subject = ""; $headers = ""; $message = ""; $splittingheaders = true; for ($i=0; $i < count($lines); $i++) { if ($splittingheaders) { // this is a header $headers .= $lines[$i]."\n"; // look out for special headers if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) { $subject = $matches[1]; } if (preg_match("/^From: (.*)/", $lines[$i], $matches)) { $from = $matches[1]; } } else { // not a header, but message $message .= $lines[$i]."\n"; } if (trim($lines[$i])=="") { // empty line, header section has ended $splittingheaders = false; } } $ForwardTo = 'aaaa@gmail.com'; mail ($ForwardTo,$subject,$message,$headers); ?> The email piping WORKS! but i'm getting bunch of MS Word html mess along with the email. is there a way to filter all that out and just have the body of the email? Quote Link to comment Share on other sites More sharing options...
discomatt Posted June 4, 2008 Share Posted June 4, 2008 Regex, probably. Without seeing this 'junk' it's hard to say. Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 4, 2008 Author Share Posted June 4, 2008 This is what I get From xxx@asd.com Wed Jun 04 14:44:08 2008 Received: from adsl-02020202002.dsl.hstntx.sbcglobal.net ([00.00.00.00]:1234 helo=prexxix) by gator465.hostgator.com with esmtpa (Exim 4.68) (envelope-from <123@cs.com>) id 1K3yu0-0005O6-Hn for 123@cs.com; Wed, 04 Jun 2008 14:44:08 -0500 From: "john" <123@cs.com> To: <aasl@cs.com> Subject: 12323213123 Date: Wed, 4 Jun 2008 14:44:15 -0500 Message-ID: <asdioj@sokd.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00E2_01C8C651.766A7CC0" X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcjGe11qMOjrcJG4R7amtFB1Cvy/Uw== Content-Language: en-us x-cr-hashedpuzzle: yYE= AdPi Axu3 BAAg ECQt EaW5 EbYl Ey7J E3EF FHiq GPV0 HF4a IH/L I8i8 JXAS KX8S;1;cwBpAGcAbgBhAGwAQABmAGkAbgBhAG4AYwBpAGEAbAAtAHIAbwBiAG8AdABpAGMAcwAuAGMAbwBtAA==;Sosha1_v1;7;{FFA2519B-E285-46B0-92BB-9425F2DC2D68};agAuAHMAdQBoAEAAZgBpAG4AYQBuAGMAaQBhAGwALQByAG8AYgBvAHQAaQBjAHMALgBjAG8AbQA=;Wed, 04 Jun 2008 19:44:13 GMT;MQAyADMAMgAzADIAMQAzADEAMgAzAA== x-cr-puzzleid: {FFA2519B-E285-46B0-92BB-9425F2DC2D68} This is a multipart message in MIME format. ------=_NextPart_000_00E2_01C8C651.766A7CC0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 1231231232 ------=_NextPart_000_00E2_01C8C651.766A7CC0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable <html xmlns:v=3D"urn:schemas-microsoft-com:vml" = xmlns:o=3D"urn:schemas-microsoft-com:office:office" = xmlns:w=3D"urn:schemas-microsoft-com:office:word" = xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" = xmlns=3D"http://www.w3.org/TR/REC-html40"> <head> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; = charset=3Dus-ascii"> <meta name=3DGenerator content=3D"Microsoft Word 12 (filtered medium)"> <style> <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:11.0pt; font-family:"Calibri","sans-serif";} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {mso-style-priority:99; color:purple; text-decoration:underline;} span.EmailStyle17 {mso-style-type:personal-compose; font-family:"Calibri","sans-serif"; color:windowtext;} .MsoChpDefault {mso-style-type:export-only;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in;} div.Section1 {page:Section1;} --> </style> <!--[if gte mso 9]><xml> <o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" /> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext=3D"edit"> <o:idmap v:ext=3D"edit" data=3D"1" /> </o:shapelayout></xml><![endif]--> </head> <body lang=3DEN-US link=3Dblue vlink=3Dpurple> <div class=3DSection1> <p class=3DMsoNormal>1231231232<o:p></o:p></p> </div> </body> </html> ------=_NextPart_000_00E2_01C8C651.766A7CC0-- Quote Link to comment Share on other sites More sharing options...
rubing Posted June 4, 2008 Share Posted June 4, 2008 so, i assume the message you sent was this? 1231231232 ??? here's for a php snippet on how to parse this kind of page: http://www.justin-cook.com/wp/2006/03/31/php-parse-a-string-between-two-strings/ basically all you want to do is return all the text between </head> & </html> and then strip out all the html. i think you are very close to solving your problem. you just need to be a little bit more patient. Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 4, 2008 Author Share Posted June 4, 2008 yes the numbers was what i sent through... i will look into what you sent and I report back my results =) so close i can smell victory!!! Quote Link to comment Share on other sites More sharing options...
rubing Posted June 4, 2008 Share Posted June 4, 2008 yup! but, you can still give me the $15 if you really want ;-) Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 4, 2008 Author Share Posted June 4, 2008 ok ... so what I'm getting as a result is a getting better. But still some crap that gets emailed... here it is... From asd@a.com Wed Jun 04 16:19:47 2008 Received: from 123123123.dsl.hs123123obal.net ([123123]:1421 helo=prexxix) by gator465.hostgator.com with esmtpa (Exim 4.68) (envelope-from <asd@aa.com>) id 1K40OY-0001MR-T5 for oskdpsk@aol.com; Wed, 04 Jun 2008 16:19:47 -0500 From: "John" <12323@ao.com> To: <asdsd@aol.com> Subject: test Date: Wed, 4 Jun 2008 16:19:54 -0500 Message-ID: <123434##.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00E7_01C8C65E.D3062580" X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcjGiLnI28Lp3X5tSLuLhc6u9F0ABA== Content-Language: en-us x-cr-hashedpuzzle: AB0P A5cy CTO+ CX7e CxSy DvBH ECBa HdzE Htgh Ic06 JKPY Jjka Jk2A KtuP LsxO L6XP;1;cwBpAGcAbgBhAGwAQABmAGkAbgBhAG4AYwBpAGEAbAAtAHIAbwBiAG8AdABpAGMAcwAuAGMAbwBtAA==;Sosha1_v1;7;{3A797A8D-B98B-4371-A084-67C4021C6B09};agAuAHMAdQBoAEAAZgBpAG4AYQBuAGMAaQBhAGwALQByAG8AYgBvAHQAaQBjAHMALgBjAG8AbQA=;Wed, 04 Jun 2008 21:19:51 GMT;dABlAHMAdAA= x-cr-puzzleid: {3A797A8D-B98B-4371-A084-67C4021C6B09} This is a multipart message in MIME format. ------=_NextPart_000_00E7_01C8C65E.D3062580 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Asidjasoijd asodj asod j ------=_NextPart_000_00E7_01C8C65E.D3062580 - Show quoted text - Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable <html xmlns:v=3D"urn:schemas-microsoft-com:vml" = xmlns:o=3D"urn:schemas-microsoft-com:office:office" = xmlns:w=3D"urn:schemas-microsoft-com:office:word" = xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" = xmlns=3D"http://www.w3.org/TR/REC-html40"> <head> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; = charset=3Dus-ascii"> <meta name=3DGenerator content=3D"Microsoft Word 12 (filtered medium)"> <style> <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:11.0pt; font-family:"Calibri","sans-serif";} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {mso-style-priority:99; color:purple; text-decoration:underline;} span.EmailStyle17 {mso-style-type:personal-compose; font-family:"Calibri","sans-serif"; color:windowtext;} .MsoChpDefault {mso-style-type:export-only;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in;} div.Section1 {page:Section1;} --> </style> <!--[if gte mso 9]><xml> <o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" /> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext=3D"edit"> <o:idmap v:ext=3D"edit" data=3D"1" /> </o:shapelayout></xml><![endif]--> </head> <body lang=3DEN-US link=3Dblue vlink=3Dpurple> <div class=3DSection1> <p class=3DMsoNormal>Asidjasoijd asodj asod j<o:p></o:p></p> </div> </body> </html> ------=_NextPart_000_00E7_01C8C65E.D3062580-- Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 4, 2008 Author Share Posted June 4, 2008 ok nvm its not working.. lol Quote Link to comment Share on other sites More sharing options...
j5uh Posted June 4, 2008 Author Share Posted June 4, 2008 ok sweet... now I've modified it even more and this is what I have: #!/usr/bin/php <?php // read from stdin $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } // handle email $lines = explode("\n", $email); // empty vars $from = ""; $subject = ""; $headers = ""; $message = ""; $splittingheaders = true; for ($i=0; $i < count($lines); $i++) { if ($splittingheaders) { // this is a header $headers .= $lines[$i]."\n"; // look out for special headers if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) { $subject = $matches[1]; } if (preg_match("/^From: (.*)/", $lines[$i], $matches)) { $from = $matches[1]; } } else { // not a header, but message $message .= $lines[$i]."\n"; } if (trim($lines[$i])=="") { // empty line, header section has ended $splittingheaders = false; } } $headers = 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-type: text/html; charset=UTF-8' . "\n"; $headers .= "From: xxx"; $ForwardTo = 'xxx'; mail ($ForwardTo,$subject,$message,$headers); ?> and I'm getting this : This is a multipart message in MIME format. ------=_NextPart_000_010F_01C8C663.3932C670 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Testing 1234 ------=_NextPart_000_010F_01C8C663.3932C670 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Testing 1234 ------=_NextPart_000_010F_01C8C663.3932C670-- Which means I've stripped away all that using this line: $headers = 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-type: text/html; charset=UTF-8' . "\n"; But how can I get rid of that other mess? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.