php laravel swift 电子邮件发送问题
php laravel swift email sending problems
我正在尝试发送一封电子邮件,但是 laravel 控制器
这是我的代码:
$email_sender = 'endritsheholli@gmail.com';
$email_pass = 'blablablablablabla';
$email_to = 'endritsheholli.a@gmail.com';
// Backup your default mailer
$backup = \Mail::getSwiftMailer();
try{
//https://accounts.google.com/DisplayUnlockCaptcha
// Setup your gmail mailer
$transport = (new Swift_SmtpTransport('smtp.gmail.com', 587))
->setUsername($email_sender)
->setPassword($email_pass);
$mailer = new Swift_Mailer($transport);
// Set t
he mailer as gmail
\Mail::setSwiftMailer($gmail);
$data['emailto'] = $email_sender;
$data['sender'] = $email_to;
//Sender dan Reply harus sama
$message = (new Swift_Message('Reset Password'))
->setFrom([$email_sender => 'EndritSheholli'])
->setTo([$email_to , 'endritsheholli.a@gmail.com' => 'ESheholli'])
->setBody('Here is the message itself')
;
$result = $mailer->send($message);
}catch(\Swift_TransportException $e){
$response = $e->getMessage() ;
echo $response;
}
返回的错误是:
Class 'App\Http\Controllers\Swift_SmtpTransport' 未找到
我已经安装了 composer 包,我在网上尝试了很多建议,但我找不到解决方案。
您必须在使用部分声明 Swift_SmtpTransport 或在您的代码中写入 class 的完整命名空间。例如:
use Swift_SmtpTransport;
// other code
或
$transport = new \Swift_SmtpTransport
我正在尝试发送一封电子邮件,但是 laravel 控制器
这是我的代码:
$email_sender = 'endritsheholli@gmail.com';
$email_pass = 'blablablablablabla';
$email_to = 'endritsheholli.a@gmail.com';
// Backup your default mailer
$backup = \Mail::getSwiftMailer();
try{
//https://accounts.google.com/DisplayUnlockCaptcha
// Setup your gmail mailer
$transport = (new Swift_SmtpTransport('smtp.gmail.com', 587))
->setUsername($email_sender)
->setPassword($email_pass);
$mailer = new Swift_Mailer($transport);
// Set t
he mailer as gmail
\Mail::setSwiftMailer($gmail);
$data['emailto'] = $email_sender;
$data['sender'] = $email_to;
//Sender dan Reply harus sama
$message = (new Swift_Message('Reset Password'))
->setFrom([$email_sender => 'EndritSheholli'])
->setTo([$email_to , 'endritsheholli.a@gmail.com' => 'ESheholli'])
->setBody('Here is the message itself')
;
$result = $mailer->send($message);
}catch(\Swift_TransportException $e){
$response = $e->getMessage() ;
echo $response;
}
返回的错误是:
Class 'App\Http\Controllers\Swift_SmtpTransport' 未找到
我已经安装了 composer 包,我在网上尝试了很多建议,但我找不到解决方案。
您必须在使用部分声明 Swift_SmtpTransport 或在您的代码中写入 class 的完整命名空间。例如:
use Swift_SmtpTransport;
// other code
或
$transport = new \Swift_SmtpTransport