我有一些问题。我需要使用SMTP发送消息,因为我想在发送时设置密码。我阅读了本手册https://octobercms.com/docs/services/mail 但我没有找到如何设置我的密码,在本手册中只设置了地址
$ message->来自('us@example.com','十月');
你可以帮助我吗?
答案 0 :(得分:0)
您需要在 config 文件夹 mail.php 文件config/mail.php
*中设置SMTP详细信息*(您可以在 config 文件夹中找到根目录,设置您的october CMS )
<?php
return [
'driver' => 'smtp', // drive need to be smtp
'host' => 'smtp.mailgun.org',
'port' => 587,
'from' => ['address' => 'noreply@domain.tld', 'name' => 'OctoberCMS'],
'encryption' => 'tls',
'username' => null,
'password' => null,
'sendmail' => '/usr/sbin/sendmail -bs',
];
根据需要设置所有详细信息并开始使用SMTP
它会driver details
时自动使用send mail
,并使用SMTP Details
use \Swift_Mailer;
use \Swift_SmtpTransport as SmtpTransport;
// Backup your default mailer so we replace it after
// sending our custom mail
$backup = Mail::getSwiftMailer();
// Setup your gmail mailer
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl');
$transport->setUsername('your_gmail_username');
$transport->setPassword('your_gmail_password');
// other config if needed...
$gmail = new Swift_Mailer($transport);
// Set the mailer as gmail
Mail::setSwiftMailer($gmail);
// Send your message
Mail::send(-- function arguments --);
// Restore your original mailer
Mail::setSwiftMailer($backup);
试试这个让我知道
答案 1 :(得分:0)
感谢您的回答。但是这个解决方案并没有解决我的问题。在我的系统中,我在发送时使用两个地址。我从管理面板使用插件进行邮件设置。此插件会从config覆盖我的设置。因此,我必须动态指定第二个邮件的所有设置,以便它们覆盖管理员在管理面板中指定的第一个邮件的设置。 对不起我的英文
答案 2 :(得分:0)
$backup = Mail::getSwiftMailer();
$smtp_host_ip = gethostbyname('my_host');
$transport = SmtpTransport::newInstance($smtp_host_ip, 465, 'ssl')->setUsername('my_username')->setPassword('my_password');
$mail = new Swift_Mailer($transport);
Mail::setSwiftMailer($mail);
Mail::send($templateMessage, $params, function($message) use ($userSendMes){
$message->from('my_address_from', 'my_name');
$message->to($userSendMes["attributes"]["email"], $userSendMes["attributes"]["name"]);
});
所有连接设置都正确