PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label swiftmailer. Show all posts
Showing posts with label swiftmailer. Show all posts

Friday, May 20, 2022

[FIXED] What are the differences between installing swiftmailer with Composer or apt?

 May 20, 2022     composer-php, php, swiftmailer, symfony     No comments   

Issue

I am using PHP Version 7.4.3 on Ubuntu 20.04.2 LTS. In its online documentation Symfony says to install swiftmailer using composer:

The recommended way to install Swiftmailer is via Composer:

$ composer require "swiftmailer/swiftmailer:^6.0"

If you are not using Symfony, does one get similar access to swiftmailer by installing it using apt?

sudo apt-get update -y && sudo apt-get install -y php-swiftmailer

Once installed with apt (it says the installed version is php-swiftmailer (5.4.2-1.1)), where is the reference documentation on the use of swiftmailer? (neither man swiftmailer nor man php-swiftmailer has a manual entry).


Solution

$ composer require "swiftmailer/swiftmailer:^6.0"

Is system agnostic and will ensure that you will always have version >= 6.x.

It is also preferable for deployments on Docker where you may be using an -alpine image which does not have apt available.

Composer will also fail the entire install if it cannot satisfy that requirment, therefore ensuring that if your app is running it has SwiftMailer.

$ sudo apt-get install -y php-swiftmailer

Will install it on a system level, so long as that system is Debian based.

It will also install it in a "global" perspective, which may be more beneficial if you're going to have multiple applications on the same server.

You likely will not know if you can use SwiftMailer until you call the class/extention and the process fails.


In short, you'll probably want to prefer the Composer method.



Answered By - Joshua
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, February 26, 2022

[FIXED] Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead

 February 26, 2022     laravel, swiftmailer     No comments   

Issue

I can't install breez and npm for this situation. What should I do to solve this problem? When I'm going to create a laravel project show this and breez install time too.

Console screen


Solution

This is just a package. You can avoid this thinks.. this is Nothing. Thanks



Answered By - Rajib Bin Alam
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, February 20, 2022

[FIXED] Yii swiftmailer fails to work in live server

 February 20, 2022     php, swiftmailer, yii, yii2     No comments   

Issue

Am using yii2 and i have setup a mailer as follows

  <?php
  return [
   'components' => [
  ....
    'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail',
        // send all mails to a file by default. You have to set
        // 'useFileTransport' to false and configure a transport
        // for the mailer to send real emails.
        'useFileTransport' => false,
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.gmail.com',
            'username' => 'myemail@gmail.com',
            'password' => 'mygmailpassword',
            'port' => '465',
            'encryption' => 'ssl',
        ],
    ],
],

];

The above works perfectly in localhost but fails when i upload to the live server i always get an error of bad credentials

The error is

Swift_TransportException

 Expected response code 250 but got code "535", with message "535-5.7.8     
Username and Password not accepted. Learn more at

535 5.7.8 https://support.google.com/mail/?p=BadCredentials 
r199sm3707144wme.1 - gsmtp

"

What could be wrong,


Solution

I use this config for gmail (and work)

        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.gmail.com',
            'username' => 'myname.mylast@gmail.com',
            'password' => 'mypass',
            'port' => '587',
            'encryption' => 'tls',
        ],


Answered By - ScaisEdge
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, February 8, 2022

[FIXED] Yii2 Swift_SmtpTransport gmail not working

 February 08, 2022     gmail, php, swiftmailer, yii, yii2     No comments   

Issue

I'm trying to send an email using yii2 mailer component.

config web.php

'mailer' => [
    'class' => 'yii\swiftmailer\Mailer',
    // send all mails to a file by default. You have to set
    // 'useFileTransport' to false and configure a transport
    // for the mailer to send real emails.
    // 'useFileTransport' => true,
    'transport' => [
        'class' => 'Swift_SmtpTransport',
        'host' => 'smtp.gmail.com',
        'username' => 'myEmail2131@gmail.com',
        'password' => 'password1234',
        'port' => '587',
        'encryption' => 'tls',
    ]
],

And my code.

Yii::$app->mailer->compose()
        ->setFrom('myEmail07@gmail.com')
        ->setTo('toSomeone@gmail.com')
        ->setSubject('Some Subject here')
        ->setTextBody('Plain text content')
        ->setHtmlBody("<p> This is the body of email</p>")
        ->send()

I'm getting this error.

Swift_TransportException Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials a13-v6sm4133042wrc.19 - gsmtp "

I already configure my Gmail account as said here enter link description here

less secure app on on your gmail account

And I also try to use ssl instead tls.

'mailer' => [
    'class' => 'yii\swiftmailer\Mailer',
    // send all mails to a file by default. You have to set
    // 'useFileTransport' to false and configure a transport
    // for the mailer to send real emails.
    // 'useFileTransport' => true,
    'transport' => [
        'class' => 'Swift_SmtpTransport',
        'host' => 'smtp.gmail.com',
        'username' => 'myEmail2131@gmail.com',
        'password' => 'password1234',
        'port' => '465',
        'encryption' => 'ssl',
    ]
],

Any idea? Thanks!


Solution

I've found a solution.

Note: I use this method just for testing. soon on production, I will use an actual email of our company.

My mail config

'mailer' => [
    'class' => 'yii\swiftmailer\Mailer',
    // send all mails to a file by default. You have to set
    // 'useFileTransport' to false and configure a transport
    // for the mailer to send real emails.
    // 'useFileTransport' => true,
    'transport' => [
        'class' => 'Swift_SmtpTransport',
        'host' => 'smtp.gmail.com',
        'username' => 'myEmail2131@gmail.com',
        'password' => 'password1234',
        'port' => '587',
        'encryption' => 'tls',
    ]
],

Then do this:

https://www.google.com/settings/security/lesssecureapps and active it. https://accounts.google.com/b/0/DisplayUnlockCaptcha and active it.

As answer from Ankit Tyagi here



Answered By - Aljay
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, January 19, 2022

[FIXED] Error after registration usnig laravel ui

 January 19, 2022     laravel, php, swiftmailer     No comments   

Issue

after i click register button i get the error bellow Swift_TransportException Process could not be started [The system cannot find the path specified. ] and whene i go to phpmyadmin it seems that i have the new user record in my database i don't know what's the relation between the auth and swiftMailer i already tried clearing the config using php artisan config:clear changing MAIL_DRIVER, MAIL_HOST, MAIL_PORT i don't know what to do

this is my .env file

APP_NAME=****
APP_ENV=local
APP_KEY=base64:****
APP_DEBUG=true
APP_URL=****

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=db
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=2525  
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_FROM_ADDRESS=from@example.com
MAIL_FROM_NAME=Example
MAIL_ENCRYPTION=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

and this is the config/mail.php

<?php

return [

    'default' => env('MAIL_MAILER', 'smtp'),
    //'default' => env('MAIL_MAILER', 'sendmail'),


    'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],

        'ses' => [
            'transport' => 'ses',
        ],

        'mailgun' => [
            'transport' => 'mailgun',
        ],

        'postmark' => [
            'transport' => 'postmark',
        ],

        'sendmail' => [
            'transport' => 'sendmail',
            'path' => '/usr/sbin/sendmail -bs',
        ],

        'log' => [
            'transport' => 'log',
            'channel' => env('MAIL_LOG_CHANNEL'),
        ],

        'array' => [
            'transport' => 'array',
        ],

        'failover' => [
            'transport' => 'failover',
            'mailers' => [
                'smtp',
                'log',
            ],
        ],
    ],

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],


    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];


Solution

I found where the error exactly is in my user model. I have this:

class User extends Authenticatable implements MustVerifyEmail

First, make sure to use the recomended MAIL_DRIVER and MAIL_HOST values. Else, look for anything that has a relation with email in your model. In my case, I simply removed the inmplements.

class User extends Authenticatable implements MustVerifyEmail
```
to
```
class User extends Authenticatable
```


Answered By - Salamah Salamah
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, January 12, 2022

[FIXED] Extension YiiMaill (Swiftmailer) can't send SMTP from gmail

 January 12, 2022     email, php, swiftmailer, yii, yii-extensions     No comments   

Issue

I've a PHP application that's running with Yii Framework and it's using the YiiMail extension that's is based in Swiftmailer.

My application was working perfectly yesterday, but today the follow error was launched:

fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

My Yii app config:

'mail' => 
  array('class' => 'application.extensions.yii-mail.YiiMail',
        'transportType' => 'smtp', 
        'transportOptions' => array(
             'host' => 'smtp.gmail.com', 
             'username' => '**@gmail.com', 
             'password' => '***', 
             'port' => '465', 
             'encryption'=>'tls' ), 
         'viewPath' => 'application.views.mail', 
         'logging' =>false, 
         'dryRun' => false
 )

ANSWER: A FAST SOLUTION

My app is running in Windows, so I did a fast configuration to solve this problem at moment.

I did a configuration with sendmail and it enable into my php.ini file.

Ps: The main problem is if you have many apps running in the same php. How don't this problem to me, it's is stand alone application, I just did.

Something like this:

sendmail.ini

[sendmail]
smtp_server=smtp.gmail.com
smtp_port = 587
#default_domain = gmail.com it's is not necessary
auth_username= your gmail@gmail.com
auth_password=your password

php.ini

[mail function]
sendmail_path = "path to sendmail installation"
SMTP = smtp.gmail.com
smtp_port = 587

Solution

If your current config was previously working, then suddenly stopped. Consider looking into the following:

  • Generating an APP password for a gmail account

  • Enabling Less SecureApps settings for your gmail account

I have encountered a similar problem before, enabling Less Secure Apps, then when I set 2 Step Verification for my google account, it stopped working.

Then generating an APP password, did the trick!



Answered By - Mark Ryan Orosa
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, January 8, 2022

[FIXED] Expected response code 220 but got code "", with message "" in Laravel

 January 08, 2022     email, laravel, php, swiftmailer     No comments   

Issue

I am using Laravel Mail function to send email. The following is my app/config/mail.php file settings.

'driver' => 'sendmail',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'email@gmail.com', 'name' => 'MyName'),
'encryption' => 'tls',
'username' => 'myUsername',
'password' => "password",
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,

Controller Mail Method

//Send Mail     
Mail::send('sendMail', array('key' => 'value'), function($message)
{
    $message->to('EmailId@hotmail.com', 'Sender Name')->subject('Welcome!');
});

When I run the code it gives me following error message:

Swift_TransportException

Expected response code 220 but got code "", with message ""

I have created a SendMail.php file in view which contains some data.

How do I resolve this error message?


Solution

This problem can generally occur when you do not enable two step verification for the gmail account (which can be done here) you are using to send an email. So first, enable two step verification, you can find plenty of resources for enabling two step verification. After you enable it, then you have to create an app password. And use the app password in your .env file. When you are done with it, your .env file will look something like.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=<<your email address>>
MAIL_PASSWORD=<<app password>>
MAIL_ENCRYPTION=tls

and your mail.php

<?php

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.gmail.com'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => '<<your email>>', 'name' => '<<any name>>'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,

];

After doing so, run php artisan config:cache and php artisan config:clear, then check, email should work.



Answered By - Sid
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing