更改PHP pear邮件中的电子邮件标题

时间:2018-11-26 20:45:32

标签: php email pear email-headers

我的PHP需要一些帮助。当我给自己发送电子邮件进行测试时,我可以在标题中看到Received: from localhost

这是显示的内容:

Received: from localhost ([107.191.96.136]) by appmaildev.com with Microsoft SMTPSVC(8.5.9600.16384);
     Mon, 26 Nov 2018 20:13:27 +0000
Received: from localhost (gateway1.mydomain.com [104.128.226.35])
    by mail.mydomain.com (Postfix) with ESMTPSA id E30387B8AB8A
    for <test-296da7c1@appmaildev.com>; Mon, 26 Nov 2018 15:13:25 -0500 (EST)

这是我要实现的目标:

Received: from mail.mydomain.com (gateway1.mydomain.com [104.128.226.35])
        by mail.mydomain.com (Postfix) with ESMTPSA id E30387B8AB8A
        for <test-296da7c1@appmaildev.com>; Mon, 26 Nov 2018 15:13:25 -0500 (EST)

代码如下:

<?php
require_once "Mail.php";

$from = "Chris <rob@mydomain.com>";
$to = "Rob Smith <test-29634da7c1@appmaildev.com>";
$subject = "Test email number 4";
$body = "Hey Ben,

I am writing to you that someone have told me you have receive my email in your inbox.

I am interested to know how you have done it exactly??

Please let me know how you did it.

Thanks,
Rob";


$host = "smtp.mydomain.com";
$port = "587";
$username = "myusername";
$password = "mypassword";


$headers = array ('From' => $from, 
    'To' => $to, 'Subject' => $subject,
    'Reply-To' => $from,
    'Content-type' => 'text/html; charset=iso-8859-1\r\n\r\n',
    'MIME-Version' => '1.0',
    'Date'  => date("r"),
    'Message-ID' => sprintf("<%s.%s@%s>",
            base_convert(microtime(), 10, 36),
            base_convert(bin2hex(openssl_random_pseudo_bytes(8)), 16, 36),
            'mydomain.com'));

$params = array ('host' => $host,
    'port' => $port,
    'auth' => 'PLAIN', // Note 1
    'socket_options' => array('ssl' => array('verify_peer_name' => false, 'verify_peer' => false)), // Note 2
    'username' => $username,
    'password' => $password);

$smtp = Mail::factory ('smtp', $params);
$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
} else {
  echo("<p>Email has been sent!</p>");
}
?>

我正在使用pear php向自己发送电子邮件。

您知道如何从Received: from localhost更改为Received: from mail.mydomain.com吗?

如果是这样,请您举个例子说明如何删除本地主机?

1 个答案:

答案 0 :(得分:1)

从内存来看,问题不在于您的代码,而在于您使用的本地托管邮件服务器。

几年前,我遇到过类似的问题。详细信息是什么(例如,它是本地的,什么软件包等)。

我所做的是告诉localhost告诉其他服务器(在您的情况下)为“ mail.mydomain.com”。