【问题标题】:Change email headers in PHP pear mail更改 PHP 梨邮件中的电子邮件标题
【发布时间】:2019-04-28 13:12:56
【问题描述】:

我的 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吗?

如果是这样,你能告诉我我应该使用什么来删除本地主机吗?

【问题讨论】:

  • 你是从本地主机发送的吗?
  • 是的,我使用 PHP 从我的网络主机发送。我可以做些什么来删除 localhost 以将其替换为mail.mydomain.com
  • 不,这是邮件服务器设置,您无法更改它——您为什么要更改?只有垃圾邮件发送者这样做

标签: php email pear email-headers


【解决方案1】:

根据记忆,问题不在于您的代码,而在于您正在使用的本地托管邮件服务器。

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

我所做的是告诉本地主机告诉其他服务器它是(在你的情况下)“mail.mydomain.com”。

【讨论】:

猜你喜欢
  • 2012-03-20
  • 2023-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-05
  • 1970-01-01
  • 2018-01-12
相关资源
最近更新 更多