gpt4 book ai didi

php - 在 Codeigniter 3 中通过 Office365 帐户发送电子邮件 - 连接超时

转载 作者:行者123 更新时间:2023-12-02 06:56:06 28 4
gpt4 key购买 nike

我正在尝试连接到我的 Office365 帐户并在 Codeigniter 3 中发送电子邮件:

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_user'] = '****';
$config['smtp_pass'] = '****';
$config['smtp_port'] = '587';
$config['smtp_timeout'] = '60';
$config['smtp_crypto'] = 'tls';
$config['mailtype'] = 'html';
$this->email->initialize($config);

$this->email->from('****', '****');
$this->email->to('****');

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');

$this->email->send(FALSE);

$this->email->print_debugger();

此代码在我的本地服务器 (wamp) 上运行良好,但在我的生产服务器 (Debian) 上运行不正常,这就是为什么我怀疑服务器上的某些设置需要更改。我得到的是:

A PHP Error was encountered

Severity: Warning

Message: fsockopen(): unable to connect to smtp.office365.com:587 (Connection timed out)

Filename: libraries/Email.php

Line Number: 1949

我也尝试用 Phpmailer 类发送邮件,我得到了相同的结果;在我的本地机器上工作,而不是在生产服务器上工作。

Codeigniter 类使用函数 fsockopen 连接到邮件服务器,但我找不到解决方案,因为我不太了解服务器配置。

如有任何建议,我们将不胜感激!

最佳答案

以下是过去对我有用的方法:

<?php 
$config['smtp_crypto'] = 'tls';
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_user'] = 'USER@EMAIL.COM';
$config['smtp_pass'] = 'password';
$config['smtp_port'] = '587';
$config['charset']='utf-8'; // Default should be utf-8 (this should be a text field)
$config['newline']="\r\n"; //"\r\n" or "\n" or "\r". DEFAULT should be "\r\n"
$config['crlf'] = "\r\n"; //"\r\n" or "\n" or "\r" DEFAULT should be "\r\n"
?>

还要注意FROM地址必须和smtp_user一样

关于php - 在 Codeigniter 3 中通过 Office365 帐户发送电子邮件 - 连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31116129/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com