So I am trying to use the SMS (text message) function in Laravel / Twilio - I have a local machine which I tested it on and the credentials and everything works fine- I use the same code on my remote machine (which worked fine yesterday) and today I am getting an error: "Error: Credentials are required to create a Client"
I have triple confirmed the credentials are correct, I have even hard coded them into the code , I have moved them from the env file to config file and still not working - I have retested my local machine and it works still - I have copied the code from local machine (working) to remote machine and still not working - the only difference between the two is I have changed the SMTP settings in the env file (even if I remove this , the problem still exists). I have cleared cache, restarted services.
my .env file
TWILIO_SID=xxxxxxxxxx
TWILIO_TOKEN=xxxxxxxxxxxxxxx
TWILIO_FROM=+1xxxxxxxxxxxxx
my Twiliocontroller:
public function smsSend()
{
$receiverNumber = "+111111111";
$message = "Sup Dude";
try {
$account_sid = getenv("TWILIO_SID");
$auth_token = getenv("TWILIO_TOKEN");
$twilio_number = getenv("TWILIO_FROM");
$client = new Client($account_sid, $auth_token);
$client->messages->create($receiverNumber, [
"from" => $twilio_number,
"body" => $message,
"statusCallback" => "https://webhook.site/xxxxxxxxxxxxxx"
]);
dd('SMS Sent Successfully.');
} catch (Exception $e) {
dd("Error: " . $e->getMessage());
}
}
My web.php
Route::get('/smssend', [TwilioController::class, 'smsSend'])->name('smsSend');
Any help would be greatly appreciated
Related
In facts I found this question: Laragon and Laravel - sendmail not working ... but I decided to post a detailed new question, to get a response, that this issue is possibly a laravel bug... Thank you.
OS: Windows 10
Laravel Version: 8.75
PHP Version: 7.4.27
Database Driver & Version: sqlite
Description:
I trying around getting sendmail (Laragon) to work, but without luck.
File '.env' got adjusted to use sendmail instead of smtp on a fresh laravel project.
Steps To Reproduce:
created new laravel project
laravel new test
adjusted .env file:
MAIL_MAILER=sendmail
MAIL_SENDMAIL_PATH='C:\LARAGON\bin\sendmail\sendmail.exe -bs'
run command:
php artisan tinker
run tinker command:
Mail::raw('Hello World!', function($msg) {$msg->to('mail#example.com')->subject('Test Email'); });
After running the tinker command, the cmd is hanging...
Also tried different options on the sendmail flags:
sendmail.exe -t -i <<< tinker hangs
sendmail.exe -t <<< tinker hangs
sendmail.exe -bs <<< tinker hangs
I can see that the sendmail.exe is running (in task manager), but seems not be able to finish (waited several minutes).
Cancelation (CTRL-c) will close the tinker session and the sendmail.exe ist terminated.
With other php built-in mail function Laragon is working fine and also successfully catching the sent mails in the mail folder.
I always tried to clear configuration cache after every change of the .env file.
php artisan config:clear
Sending mail via php works fine as expected with the following code:
<html>
<head>
<title>Sending HTML email using PHP</title>
</head>
<body>
<?php
$to = "xyz#somedomain.com";
$subject = "This is subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:abc#somedomain.com \r\n";
$header .= "Cc:afgh#somedomain.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
?>
</body>
</html>
Any help really appreciated.
Generally this happens when there is an authentication issue with sendmail.
Make sure you have setup sendmail with your gmail credentials, as suggested by the Laragon Documentation
Additionally, gmail disables "less secure apps" by default. Make sure your account has less secure apps enabled here too (or even better, use an Application Specific Password): https://myaccount.google.com/lesssecureapps
output phpinfo() and check if you have the exact location define on sendmail_path
you also need to define it inside config/mail.php like
'sendmail' => [
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs',
],
or pull the value from your .env file MAIL_SENDMAIL_PATH
'path' => env('MAIL_SENDMAIL_PATH')
Additionally, you may try using smtp driver with localhost info in your .env file, you can see these details in phpinfo() as well
MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null
try creating a route to send the email or dump the error
Route::get('/test-mail', function () {
try {
$send = \Illuminate\Support\Facades\Mail::mailer('sendmail')->send([], [], function ($message) {
$message
->to('to#email.com')
->from('from#email.com', 'Test')
->subject( 'My Subject' )
->setBody('Test Content', 'text/html');
});
dd($send);
} catch (\Exception $e ) {
throw new \Exception( $e->getMessage() );
}
});
I'm building a website using Laravel 8 and Goutte 4. I'm trying to send a request to a website that requires authentication with a .pem file. In order to do so, I include the 'local_cert' param when creating the instance of http-client like this:
use Goutte\Client;
use Symfony\Component\HttpClient\HttpClient;
class Query
{
protected $client;
public function __construct() {
$this->client = (new Client(
HttpClient::create([
'timeout' => 30,
'local_cert' => //absolute path to the .pem file,
])
));
}
public function query() {
$this->client->request('GET', "https://palena.sii.cl/cvc_cgi/dte/of_solicita_folios");
}
}
This works perfectly well on my local server, but when I try it on the production server, I get an Exception: "Problem with the local SSL certificate". The .pem file being used is the same in development and production, and the php can read the file in the production server.
The full error in the laravel Log is:
[2020-12-02 21:32:30] production.ERROR: Problem with the local SSL certificate for "https://palena.sii.cl/cvc_cgi/dte/of_solicita_folios". {"userId":1,"exception":"[object] (Symfony\Component\HttpClient\Exception\TransportException(code: 0): Problem with the local SSL certificate for "https://palena.sii.cl/cvc_cgi/dte/of_solicita_folios". at /my/path/vendor/symfony/http-client/Chunk/ErrorChunk.php:65)
did you fixed? i only make this work with GuzzleHttp
$requestAuthentication = $clientAuth->request('GET', $urlAuthentication, [
'cert' => [$rutaPem, 'clave'],
'cookies' => $cookiesAuth,
]);
I am trying to install Prestashop on my local machine
Using ubuntu 18.04, php 7.2, mysql 5.6, apache 2.4
I have cloned from their github repo, checkouted to branch 1.7.6.x, installed composer dependencies and made a symbolic link to the code directory from my /var/www/html (didn't want to bother creating a vhost)
Opened chromium to http://127.0.0.1/prestashop/install-dev/index.php
Proceeded with all steps, with correct mysql settings, directory permission settings, left the language to English (English)
But during the Store Installation step, when "Installing addons modules", it fails with a curl error like this:
file_get_contents_curl failed to download http://i18n.prestashop.com/translations/1.7.6.7/en-US/en-US.zip : (error code 28) Operation timed out after 5001 milliseconds with 221832 out of 516048 bytes received
I also have the following info in the Request tab of my inspector:
It's calling http://127.0.0.1/prestashop/install-dev/index.php?installModulesAddons=true&_=1596718771175 with status_code 200
I have the following as response body in there:
{
"success":false,
"message":"file_get_contents_curl failed to download http:\/\/i18n.prestashop.com\/translations\/1.7.6.7\/en-US\/en-US.zip : (error code 28) Operation timed out after 5001 milliseconds with 221832 out of 516048 bytes received"
}
I checked the file in install-dev/controllers/http/process.php but the code that I think is called just looks like this:
/**
* PROCESS : installModulesAddons
* Install modules from addons
*/
public function processInstallAddonsModules()
{
$this->initializeContext();
if (($module = Tools::getValue('module')) && $id_module = Tools::getValue('id_module')) {
$result = $this->model_install->installModulesAddons(array('name' => $module, 'id_module' => $id_module));
} else {
$result = $this->model_install->installModulesAddons();
}
if (!$result || $this->model_install->getErrors()) {
$this->ajaxJsonAnswer(false, $this->model_install->getErrors());
}
$this->session->process_validated = array_merge($this->session->process_validated, array('installModulesAddons' => true));
$this->ajaxJsonAnswer(true);
}
I suspect my faulty internet is to blame, but is there a workaround to increase the curl timeout?
Comment the code lines like this:
I am getting the error below when i try to upload a file greater than 25mb to amazon s3 using laravel aws sdk, however files below 25mb are uploading successfully. I have everything setup correctly in my .env file. I have no idea why this is happening.
Any help would be appreciated.
Error:
Error executing "ListObjects" on
"bucketdomain/?prefix=b6d767d2f8ed5d21a44b0e5886680cb9%filename%2F&max-keys=1&encoding-type=url";
AWS HTTP error: cURL error 7: Failed to connect to bucketdomain
port 443: Network unreachable (see
http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Save function in laravel:
$v = Storage::disk('s3')->put($path, file_get_contents($file), 'public');
unlink($file->getPathname());
return response()->json(["message" => "File uploaded successfully!"]);
Upload function in laravel:
if ($receiver->isUploaded() === false) {
throw new UploadMissingFileException();
}
$save = $receiver->receive();
if ($save->isFinished()) {
database entries...
return $this->saveChunkFile($file,$userFolderName,$path,$fileName);
}
$handler = $save->handler();
return response()->json([
"Percentage" => $handler->getPercentageDone()
]);
I am using reusable.js in client side to upload files in chunks & the code above is to handle the chunks and merge them when done and pass to the saveChunkFile function.
Picture:
The file is to be stored in the 2nd folder from top but there is not file that is why i think the error is thrown on size function and these files (chunks) are being generated and not stopping still.
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.