电子邮件未在localhost中以cakephp 3.x格式发送
这里我尝试从localhost发送电子邮件。我已经在php.ini和sendmail.ini文件中配置了smtp服务器设置。我的代码更改如下 app.php电子邮件未在localhost中以cakephp 3.x格式发送,php,cakephp,Php,Cakephp,这里我尝试从localhost发送电子邮件。我已经在php.ini和sendmail.ini文件中配置了smtp服务器设置。我的代码更改如下 app.php 'EmailTransport' => [ 'default' => [ 'className' => 'Smtp', // The following keys are used in SMTP transports 'host'
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => '******',
'password' => '********',
// 'client' => null,
// 'tls' => null,
],
],
'Email' => [
'default' => [
'transport' => 'default',
'from' => '**********',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],
控制器代码
$email = new Email('default');
try {
$res = $email->from('*****@**.**')
->to(['*****@**.**' => 'My Website'])
->subject('Tsting')
->send("hiii this is for testing ");
} catch (Exception $e) {
echo 'Exception : ', $e->getMessage(), "\n";
}
我做了一些调查,他们说邮件也会从本地主机发送。。有人能帮我一下吗?运行此代码时会出现什么错误/异常?在哪里定义了
localhost
?在localhost上运行代码对我很有效。您是否将电子邮件类包含在控制器的顶部?使用Cake\Network\Email\Email;