我正在开发一个有多个用户的 Web 应用程序,但我在发送电子邮件时遇到了一些问题。发送工作正常,没有问题,但问题是访问者和用户之间的每次邮件交互都会发送到 env 文件中规定的管理员电子邮件地址。我正在使用 gmail 发送,Laravel 8。例如,访问者 A 向用户 B 发送了一条消息。用户 B 正确收到了邮件,但管理员也收到了消息。感谢帮助。
这是我的电子邮件控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mail;
class EmailsController extends Controller
{
public function send(Request $request)
{
function sentence_case($string) {
$sentences = explode(" ",$string);
$sentences = array_reverse($sentences);
$new_string = '';
foreach ($sentences as $key => $sentence) {
$new_string = ucfirst(mb_strtolower(trim($sentence)))." ".$new_string;
}
return $new_string;
}
$this->validate($request, [
'ime' => 'required', //visitor name
'email' => 'required', // visitor email address
'poruka' => 'required' //visitor message
]);
$ime = $request->get('ime');
$ime = sentence_case($ime);
$email = $request->get('email');
$poruka = $request->get('poruka');
Mail::send('emails.message', [
'name' => $ime,
'email' => $email,
'comment' => $poruka ],
function ($m) use ($email) {
$m->from($email);
$m->to('usersemail@yahoo.com', 'MyApp')
->subject('Website Contact Form');
});
/* usersemail@yahoo.com is registered user email address different from aplication admin/owner email addres stated in env file, but admin receives this message */
if (Mail::failures()) {
return response()->Fail('Sorry! Please try again latter');
}else{
return back()->with('success', 'Thanks for contacting me, I will get back to you soon!');
}
}
}