Symfony confirmation email not send but gmail work - swiftmailer

i have some probleme using swiftmailer for setting my confirmation email, normaly everything is set well, but the mail is not sent, and i have my user in my database (but enable is set to 0 of course).
Since i don't have errors show by symfony i suppose it's my gmail account that blocked them, but i already set it to allow other application to use it as a "server", and i have a page that use swiftmailer to send normal mail, and it work fine.
i'm lost, thanks for your future help
My config.yml :
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
encryption: ssl
fos_user:
db_driver: orm
firewall_name: main
user_class: UserBundle\Entity\User
service:
mailer: fos_user.mailer.default
registration:
confirmation:
enabled: true
from_email:
address: maxime.duvey#gmail.com
sender_name: Registration mail
My config.yml :
mailer_transport: gmail
mailer_host: 127.0.0.1
mailer_user: maxime.duvey#gmail.com
mailer_password: XXXXXXXXXXX
i'm really lost, i don't understand why it don't work

It might be because you have to turn on "Less Secure Apps" as gmail allows doesn't allow you to access logins unless it is a secure app that they provide. This can be found in you google admin console.
See the link here for more info
I had the same problem when using PHPMailer.
However if you do decide to turn it on, it is not recommended.
They mention this in the link provided.

now that i think of it, it's maybe my manner to add a new user to my database :
my controler :
$userregister = new User();
$formregister = $this->get('form.factory')->createBuilder(FormType::class, $userregister);
$formregister
->add('firstname', TextType::class)
->add('lastname', TextType::class)
->add('email', EmailType::class)
->add('phonehome', NumberType::class)
->add('phoneportable', NumberType::class)
->add('username', TextType::class)
//->add('Password', PasswordType::class)
->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat Password'),
))
->add('submit', SubmitType::class);
$form = $formregister->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->persist($userregister);
$em->flush();
$request->getSession()->getFlashBag()->add('notice', 'Annonce bien enregistrée.');
return $this->redirect($this->generateUrl('Contact_Action', array('id' => $userregister->getId())));
}
return $this->render('register.html.twig', array('form'=>$form->createView()));
and my twig :
{{ form(form) }}
i'm not sure, maybe

Related

How to fix 'Facebook has detected MyApp isn't using a secure connection to transfer information.' error in Laravel

I am trying to connect my app to facebook login with Laravel and socialite package.But i don't know why facebook show me this error. I searched internet but i couldn't find anything .How can i fix this error ?
I thought that if i make my connection with https it will work but after making https again error appears.
My code in laravel:
web.php
Route::get('login/{provider}', 'SocialController#redirect');
Route::get('login/{provider}/callback','SocialController#Callback');
SocialController.php
public function redirect($provider)
{
return Socialite::driver($provider)->redirect();
}
public function Callback($provider){
$userSocial = Socialite::driver($provider)->stateless()->user();
$users = User::where(['email' => $userSocial->getEmail()])->first();
if($users){
Auth::login($users);
return redirect('/');
}else{$user = User::create([
'username' => $userSocial->getName(),
'email' => $userSocial->getEmail(),
'provider_id' => $userSocial->getId(),
'provider' => $provider,
]);
return redirect()->route('home');
}
}
You can do "Create Test App" and replace your App ID and Secret using the test app.
The simple answer is - Facebook will send sensitive data to provided redirect_uri, so it is ensuring this connection is private, by forcing you to use valid SSL.
As long as you do not setup a valid domain with proper certificate, Facebook won't let you use production API.
It looks like time expiration. I've just created another Facebook app and it works without that error.
You can use ngrok to make your localthost https.
download and run ngrok.exe.
Then run command ngrok.exe http {port}. In most cases, it will be 8000.
In case of angular : try to serve your app in secured socket layer true mode as Facebook is detecting insecure connection
Use the following command:
ng serve --ssl true

Laravel issue Credentials are required to create a Client

I need to test send SMS to mobile I get Credentials are required to create a Client error for My Code Here
.env
TWILIO_ACCOUNT_SID=AC15...................
TWILIO_AUTH_TOKEN=c3...................
TWILIO_NUMBER=+1111...
Config\App
'twilio' => [
'TWILIO_AUTH_TOKEN' => env('TWILIO_AUTH_TOKEN'),
'TWILIO_ACCOUNT_SID' => env('TWILIO_ACCOUNT_SID'),
'TWILIO_NUMBER' => env('TWILIO_NUMBER')
],
Controller
$accountSid = env('TWILIO_ACCOUNT_SID');
$authToken = env('TWILIO_AUTH_TOKEN');
$twilioNumber = env('TWILIO_NUMBER');
$client = new Client($accountSid, $authToken);
try {
$client->messages->create(
'0020109.....',
[
"body" => 'test',
"from" => $twilioNumber
// On US phone numbers, you could send an image as well!
// 'mediaUrl' => $imageUrl
]
);
Log::info('Message sent to ' . $twilioNumber);
} catch (TwilioException $e) {
Log::error(
'Could not send SMS notification.' .
' Twilio replied with: ' . $e
);
}
Twilio developer evangelist here.
A quick read over the environment config for Laravel suggests to me that you can use the env method within your config files, as you are doing, but it's not necessarily available in application code. Since you are committing your environment variables to the config object, I think you need to use the config method instead.
$accountSid = config('TWILIO_ACCOUNT_SID');
$authToken = config('TWILIO_AUTH_TOKEN');
$twilioNumber = config('TWILIO_NUMBER');
Let me know if that helps at all.

Swiftmailer Symfony 3 : 1 email sent but nothing appear

I'm trying to send an email with symfony 3, swiftmailer and twig.
I'm doing a form with formbuilder and when someone click on the submit button, it send the mail. I don't have an error, only a "1 spooled message".
What I've tried : I did : php bin/console swiftmailer:email:send
It returns : [OK] 1 emails were successfully sent. (also here i've no mail).
In my two boxes I have allowed less restrictions for connexions.
My code looks like :
For the controller :
/**
* #Route("testmail", name="testmail")
*/
public function testmail(Request $request)
{
$societe = null;
$form = $this->createFormBuilder()
->add('Societe', TextType::class, array('label' => 'Société'), array('constraints' => array(new NotBlank(array()),
new Length(array('min' => 2,
'max' => 25)))))
-> add('send',SubmitType::class, array('label' => 'Cotation'))
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
if ($request->isMethod('POST')) {
$societe = $form["Societe"]->getData();
$message = \Swift_Message::newInstance()
->setSubject('Etude Financiere')
->setFrom('wolffvianney#gmail.com')
->setTo('vianney.wolff#yahoo.fr')
->setCharset('utf-8')
->setContentType('text/html')
->setBody($this->render('#gkeep/Finance/email.html.twig', array('Societe' => $societe)));
$this->get('mailer')->send($message);
}
}
return $this->render('#gkeep/Finance/finance.html.twig', array('form' =>$form->createView(),
'Societe'=>$societe));
}
the config.yml :
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
the parameters.yml :
mailer_transport: mail
mailer_host: smtp.gmail.com
mailer_user: wolffvianney#gmail.com
mailer_password: *mypasswordforwolffvianney#gmail.com*
secret: thesecret
the Finance/email.html.twig
<html>
hi
société : {{ Societe }}
</html>
if anyone has any advices or help, I can send other files if needed. I don't understand what is wrong, thanks for advance. (I also tried to delete the line spool{type:memory
it says then that 1 email has been sent but here also, I don't receive any mails.
Vianney
Try
php bin/console swiftmailer:spool:send --env={your_env}

Getting Unauthorized error trying to send email with Sparkpost (Laravel 5.4)

I've been following the Laravel Mail docs https://laravel.com/docs/5.4/mail to send email via a SparkPost account. When I try and send I'm getting
ClientException
Client error: `POST https://api.sparkpost.com/api/v1/transmissions` resulted in a `401 Unauthorized` response:
{"errors": [ {"message": "Unauthorized."} ]}
As per the docs I've got the sparkpost key in config/services.php and though the docs don't mention anything about it (why not!?) a bit of Googling convinced me to set the mail driver etc. in my .env file. I then have a web route to check the config being used,
Route::get('test', function()
{
dd(Config::get('mail'));
});
which gives
array:9 [▼
"driver" => "sparkpost"
"host" => "smtp.sparkpostmail.com"
"port" => "587"
"from" => array:2 [▶]
"encryption" => "tls"
"username" => "my-sparkpost-account-login-email-address"
"password" => "my-sparkpost-account-login-password"
"sendmail" => "/usr/sbin/sendmail -bs"
"markdown" => array:2 [▶]
]
I actually want to use a mailable and views which I've set up, but just to test the sending I bypassed these and set the following route to test:
Route::get('/sparkpost', function () {
Mail::send('emails.test', [], function ($message) {
$message
->from('marketing#my-sparkpost-sending-domain.com', 'Me')
->to('my-email-address', 'My-Name')
->subject('A Test Email');
});
});
which got the error at the top (testing with my mailables and views gave the exact same error which makes me think they are correctly set up - assuming the above test route is correct).
The on thing I'm wondering about is I'm testing on my local machine, so test URL is http://localhost/seg/public/sparkpost - I'm wondering if this is tripping SparkPost up (i.e. do I have to actually be sending from a server running at the same domain as the sending domain configured in sparkpost, or is it just the sending address in the email that has to match?)
Thanks for any suggestions!
if you use smtp driver,
You need go to Account > SMTP Relay to get credentials for SMTP,
it's not your sparkpost account credentials.
if you use sparkpost driver,
you need put api key of sparkpost into config/services.php, there is no need to input smtp username and password if you use sparkpost driver

How to create user on domain with Google apps marketplace API?

We have application published with Google apps marketplace. we need to create user on domain where they install our app through API. I have tied the following php code but, i am getting 401 error. Please help.
$oauthOptions = array(
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
'version' => '2.0', 'scope' => '',
'signatureMethod' => "HMAC-SHA1",
'consumerKey' => 'marketplace oauth consumer key',
'consumerSecret' => 'marketplace oauth consumer secret key' );
$consumer = new Zend_Oauth_Consumer($oauthOptions);
$token = new Zend_Oauth_Token_Access();
$token->setToken('');
$token->setTokenSecret('');
$client = $token->getHttpClient($oauthOptions);
$gdata = new Zend_Gdata_Gapps($client, 'domain name');
$gdata->createUser('user34', 'fistname', 'familyname', 'Password');
You're using the wrong OAuth version - the consumer key and secret work with 1.0, not 2.0. You also don't need to set the scope, token, or token secret to empty strings but I'm not certain whether that would actually cause any problems.
There's a working example of doing two-legged OAuth in PHP at http://code.google.com/p/google-mail-xoauth-tools/source/browse/trunk/php/two-legged.php. It isn't a marketplace application but the authentication is the same so it should be a good starting point.

Resources