简体   繁体   English

从PHP脚本使用客户端证书(无密码)连接到SMTP服务器并发送电子邮件

[英]Connect to smtp server with client certificate (without password) from php script and send email

I need to implement a script to send emails on behalf of an existing email server. 我需要实现一个脚本来代表现有电子邮件服务器发送电子邮件。 The emails server supports only one way of authentication which is "Client Certificate Authentication". 电子邮件服务器仅支持一种身份验证方式,即“客户端证书身份验证”。 I only have an email address and a certificate to authenticate through my php script (no password), and send emails. 我只有一个电子邮件地址和一个证书,可以通过我的php脚本进行身份验证(没有密码),并发送电子邮件。 and that is the only thing I know about the server :(. 那是我对服务器:(。

I have not much idea about client certificate authentication, have searched over already but could not find any useful documents for the particular case. 我对客户端证书身份验证没有太多了解,已经进行了搜索,但是找不到针对特定情况的任何有用的文档。

Can some buddy pleas point me to the right direction ? 可以通过一些好友请求将我指向正确的方向吗?

Good question. 好问题。 This is a bit of a guess, but I would expect that you need to disable normal auth and provide the client cert via the stream context options passed to the TLS connection. 这只是一个猜测,但是我希望您需要禁用普通身份验证,并通过传递给TLS连接的流上下文选项提供客户端证书。

I suggest these changes over a regular PHPMailer SMTP+STARTTLS connection: 我建议通过常规的PHPMailer SMTP + STARTTLS连接进行以下更改:

$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SMTPAuth = false;
$mail->SMTPOptions = [
    'ssl' => [
        'verify_peer'  => true,
        'local_cert' => '/path/to/client_cert_and_key.pem'
    ]
];

The local cert file should contain both the client private key and certificate in PEM format. 本地证书文件应同时包含客户端私钥和PEM格式的证书。

Look at this example for more complete code that uses SSL stream context options. 此示例中查看使用SSL流上下文选项的更完整的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有安装SMTP服务器的情况下从PHP发送邮件? - How to send email from PHP without SMTP server installed? PEAR使用具有SMTP身份验证的远程服务器从PHP脚本发送电子邮件 - PEAR to send email from PHP script using a remote server with SMTP authentication 如何从本地主机发送电子邮件而不与外部SMTP服务器同步? - How to send email from localhost without synchronizing with external SMTP server? 从 PHP 页面使用 GMail SMTP 服务器发送电子邮件 - Send email using the GMail SMTP server from a PHP page PHP使用客户端IP连接到SMTP服务器 - PHP Use Client IP to connect to smtp server 如何在没有 SMTP 的情况下从 PHPMAILER 发送电子邮件 - How send email from PHPMAILER without SMTP 从SMTP远程服务器CakePHP 3发送电子邮件 - Send Email from SMTP remote server CakePHP 3 使用外发邮件服务器,用户名和密码验证从PHP发送电子邮件 - send email from PHP with outgoing mail server & userid and password authantication 当我尝试使用 phpMailer 从 php 发送 email 时,如何解决 SMTP 连接上的错误? POP/IMAP - How to solve error on SMTP connect when I try send email from php using phpMailer? POP/IMAP 我已经配置了SMTP客户端,但是无法从WAMP服务器发送电子邮件 - Unable to send email from wamp server though i have configure smtp client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM