使用SwiftMailer

时间:2016-06-14 09:56:37

标签: php email slim swiftmailer

我正在使用Slim PHP框架并尝试通过Gmail发送电子邮件。 问题是当我发送电子邮件时,它会导致"超薄应用程序错误。"

$mailer->send($message);

这是我发送电子邮件的功能

function send_email($email)
{
    $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587,'tls')
        ->setUsername('pandala61@gmail.com')
        ->setPassword('yourpassword');

    $mailer = Swift_Mailer::newInstance($transport);


    // Create a message
    $message = Swift_Message::newInstance('Test mail')
        ->setFrom(array('from_email@gmail.com' => 'SENDER'))
        ->setTo(array('To_email@gmail.com'))
        ->setBody("Hello, test send mail");

    // Send the message
    $mailer->send($message);

} 

1 个答案:

答案 0 :(得分:0)

在使用它之前,您必须准备好您的Gmail帐户:https://support.google.com/accounts/answer/2461835?hl=en 初始化:     @Override public View getView(final int position, View convertView, ViewGroup parent) { .... //associating the data position to the button through intent to give the desc activity holder.mENDescBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(context, EnglishNewsDescriptionActivity.class); intent.putExtra("image_url", mENList.get(position).getNewsImage()); intent.putExtra("title", mENList.get(position).getNewsTitle()); intent.putExtra("date", mENList.get(position).getNewsDate()); startActivity(intent); } }); ...... return convertView; }

// Create Transport. You can use it in directly in routes.php (not good practice), in your config.php file is best. $transport = Swift_SmtpTransport::newInstance() ->setHost('smtp.gmail.com') ->setPort(465) ->setEncryption('ssl') ->setUsername('emailat@gmail.com') ->setPassword('passw') ;