ran*_*nnt 2 php email debian codeigniter
我正在尝试连接到我的 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();
Run Code Online (Sandbox Code Playgroud)
这段代码在我的本地服务器 (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
Run Code Online (Sandbox Code Playgroud)
我也尝试使用 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"
?>
Run Code Online (Sandbox Code Playgroud)
另外要注意的是FROM地址必须和smtp_user一样
| 归档时间: |
|
| 查看次数: |
10794 次 |
| 最近记录: |