给出一个电子邮件作为原始文本,我该如何使用PHP发送? [英] Given an email as raw text, how can I send it using PHP?

查看:110
本文介绍了给出一个电子邮件作为原始文本,我该如何使用PHP发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,我的邮件服务器通过STDIN发送邮件。有没有一个简单/非卷积的方式来收集原始邮件字符串,并发送/转发/转发给特定的电子邮件地址?

I've got a PHP script that my mail server is piping emails to via STDIN. Is there a straightforward/non-convoluted way to take a raw email string and send/forward/relay it to a specific email address?

我犹豫使用PHP的 mail() Pear :: Mail 因为,据我所知,我不能只是传递原始的电子邮件。我必须解析标题,从而冒着剥离或改变原始电子邮件内容的风险。

I hesitate to use PHP's mail() or Pear::Mail because, as far as I can tell, I can't just pass along the raw email. I'd have to parse the headers, thereby running the risk of stripping or altering the original email's contents.

以最小的骚扰做推荐的方法是什么原始电子邮件内容?

What would be the recommended way to do this with minimal "molesting" of the original email contents?

注意:如果没有内置的方法,有没有现有的库可能会帮助我这样做?

Note: If there isn't a built-in approach, are there any existing libraries that might help me do this?

推荐答案

我有同样的问题,但找到一个解决方案接缝工作。在PHP中打开一个套接字,然后远程登录原始的emaildata。这样的东西:

I had the same problem but found a solution that seams to work. Open a socket in PHP and "telnetting" the raw emaildata. Something like this:

  $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); 

如果你不知道,你可能需要查找mx-host。 Google有一个答案,我确定。

You might need to lookup the mx-host if you dont know it. Google has an answer to that i'm sure.

这篇关于给出一个电子邮件作为原始文本,我该如何使用PHP发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆