Given that the letter is raw text, how can I send it using PHP?

I have a PHP script that my mail server sends emails via STDIN. Is there a simple / non-confusing way to take a raw email string and send / forward / forward it to a specific email address?

I am embarrassed to use PHP mail() or Pear::Mail , because as far as I can tell, I can’t just go through the raw message. I have to parse the headers, thereby risking deleting or modifying the original content of the email.

What would be the recommended way to do this with minimal “annoyance” of the original email content?

Note. If there is no built-in approach, are there any existing libraries that could help me?

+4
source share
3 answers

I had the same problem, but I found a solution that stitches for work. Open the socket in PHP and telnetting raw emails. Something like that:

  $lSmtpTalk = array( array('220', 'HELO my.hostname.com'.chr(10)), array('250', 'MAIL FROM: me@hostname.com '.chr(10)), array('250', 'RCPT TO: you@anotherhost.com '.chr(10)), array('250', 'DATA'.chr(10)), array('354', $lTheRawEmailStringWithHeadersAndBody.chr(10).'.'.chr(10)), array('250', 'QUIT'.chr(10)), array('221', '')); $lConnection = fsockopen('mail.anotherhost.dk', 25, $errno, $errstr, 1); if (!$lConnection) abort('Cant relay, no connnection'); for ($i=0;$i<count($lSmtpTalk);$i++) { $lRes = fgets($lConnection, 256); if (substr($lRes, 0, 3) !== $lSmtpTalk[$i][0]) abort('Got '.$lRes.' - expected: '.$lSmtpTalk[$i][0]); if ($lSmtpTalk[$i][1] !== '') fputs($lConnection, $lSmtpTalk[$i][1]); } fclose($lConnection); 

You may need to find mx-host if you do not know this. Google has an answer to this, I'm sure.

+7
source

There in this article is about sending a text email using PHP. You can use the Zend / Mail.php package from the Zend Framework.

 require_once 'Zend/Mail.php'; require_once 'Zend/Validate/EmailAddress.php'; $mail=new Zend_Mail(); $validator=new Zend_Validate_EmailAddress(); ///////... $mail->setBodyText(strip_tags($_POST['message'])); $mail->setBodyHtml($_POST['message']); 

setBodyText serves as an alternate mime type header for text mail, and setBodyHtml for the hmtl version.

Hope this helps. Let us know if this works.

0
source

I ran into the same problem, the best solution I could run into (linux environment) was to connect the raw message to maildrop and provide it with the mailfilter file that just indicated the intended recipient.

With this in mind, I found that the Exchange server identifies this message as a duplicate, since one with the same identifier identifier was already in its repository, so I also redirected the refile to create a new message identifier, resulting in:

 /usr/bin/reformail -R Message-ID: Original-Message-ID: -A'Message-ID:' | /usr/bin/maildrop maildrop-file 

... sent a raw email to PHP using proc_open ()

"maildrop-file" contains nothing but

 to " !recipient@domain.com " 
0
source

All Articles