我使用Slim PHP框架并尝试通过Gmail发送电子邮件。 问题是当我发送电子邮件时,它会导致“Slim Application Error”。使用SwiftMailer通过Gmail发送电子邮件
$mailer->send($message);
这里是我的功能来发送电子邮件
function send_email($email)
{
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587,'tls')
->setUsername('[email protected]')
->setPassword('yourpassword');
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Test mail')
->setFrom(array('[email protected]' => 'SENDER'))
->setTo(array('[email protected]'))
->setBody("Hello, test send mail");
// Send the message
$mailer->send($message);
}
它抛出了什么错误? – geggleto
教程展示如何使用Swiftmailer配置和发送电子邮件。 http://sgeek.org/send-email-attachment-using-swiftmailer-symfony/ –