Using the zend mail php package to connect to Gmail and getting an error
My Method looks like
//Get all mail
public function GetMail() {
$mail = new Imap([
'host' => 'imap.gmail.com',
'ssl' => 'tls',
'port' => '993',
'user' => 'example#gmail.com',
'password' => '*********',
]);
echo $mail->countMessages() . " messages found\n";
foreach ($mail as $message) {
printf("Mail from '%s': %s\n", $message->from, $message->subject);
}
}
The error is as follows:
cannot read - connection closed?
Using Laravel as a framework
So i fixed using
$mail = new Imap(array(
'host' => 'imap.gmail.com',
'user' => 'noreply#gmail.com',
'password' => '*********',
'ssl' => 'ssl',
'port' => 993
));
$mail->countMessages();
$content = array();
foreach ($mail as $messageNum => $message) {
array_push($content, ['from' => $message->from,'subject' => $message->subject, 'id' => $message->messageId]);
}
return $content;
Related
When I try to config mail from livewire controller and send mail with foreach loop then show the error "Illuminate\Mail\MailManager::getConfig(): Argument #1 ($name) must be of type string, null given, called in /Users/msurubel/Web_Application_Projects/Lourent/Email_Marketing_App/main_app/vendor/laravel/framework/src/Illuminate/Mail/MailManager.php on line 107"
Controller Code
$getAllSubscribers = subscribers::wheregroup_id($this->SelectingGroupInput)->get();
//Config SMTP
$getSMTPConfig = smtp_configs::whereref_id($this->SelectingSMTPConfigInput)->first();
$mailConfig = array(
'mailer' => $getSMTPConfig->mailler,
'host' => $getSMTPConfig->host,
'port' => $getSMTPConfig->port,
'from' => array('address' => $this->SendingFromEmail, 'name' => $this->SendingFromName),
'encryption' => $getSMTPConfig->encryption,
'username' => $getSMTPConfig->username,
'password' => $getSMTPConfig->password,
);
Config::set('mail', $mailConfig);
foreach ($getAllSubscribers as $lists){
$getSubscriberData = subscribers::whereid($lists->id)->first();
$details = [
'CompanyName' => $this->SendingFromName,
'subject' => $this->SendingSubjectline,
'MailBody' => "Hi, How are you.",
'name' => "App",
];
Mail::to("$getSubscriberData->email")->send(new BulkMail($details));
}
This my error view - https://flareapp.io/share/x7Xp90w7#F60
I deployed a Laravel-Livewire on Digital Ocean and now I'm having a Mixed content problem when I try to upload a file.
Here is the error:
UploadManager.js:131 Mixed Content: The page at 'https://intake.freejiji.ca/clients/3/extensions' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://intake.freejiji.ca/livewire/upload-file?expires=1625251608&signature=9d98c598db4f6fccc01c009bcfc3051c6a97b56f4058f4d9489a8d30d6d497c2'. This request has been blocked; the content must be served over HTTPS.
The error happens when after I click "Select File" and chose the .csv file I want. Since I'mdoing this on a livewire component I'm not sure how to fix this so that the request goes over HTTPS instead of HTTP.
I was able to fix similar problems on the app by changing "asset()" with "secure_asset()"
and "route()" with "secure_url()" but in this case I'm not sure what to do.
Here is the whole "Import" component:
<?php
namespace App\Http\Livewire\Modals;
use Validator;
use Livewire\Component;
use App\Http\Traits\Csv;
use App\Models\AccountUser;
use Livewire\WithFileUploads;
use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\Auth;
class ImportExtensions extends Component
{
use WithFileUploads;
public $clientID;
public $showModal = false;
public $upload;
public $columns;
public $fieldColumnMap = [
'first_name' => '',
'last_name' => '',
'email' => '',
'password' => '',
'extension' => '',
'user_type' => '',
];
protected $rules = [
'fieldColumnMap.first_name' => 'required|max:255',
'fieldColumnMap.last_name' => 'required|max:255',
'fieldColumnMap.email' => 'required|max:255',
'fieldColumnMap.password' => 'required|max:255',
'fieldColumnMap.extension' => 'required|max:255',
'fieldColumnMap.user_type' => 'required|max:255',
];
protected $validationAttributes = [
'fieldColumnMap.first_name' => 'First Name',
'fieldColumnMap.last_name' => 'Last Name',
'fieldColumnMap.email' => 'Email',
'fieldColumnMap.password' => 'Password',
'fieldColumnMap.extension' => 'Extension',
'fieldColumnMap.user_type' => 'User Type',
];
public function updatingUpload($value)
{
Validator::make(
['upload' => $value],
['upload' => 'required|mimes:csv'],
)->validate();
}
public function updatedUpload()
{
$this->columns = Csv::from($this->upload)->columns();
$this->guessWhichColumnsMapToWhichFields();
}
public function import()
{
// Validate that you are importing any data
$this->validate();
$importCount = 0;
Csv::from($this->upload)
->eachRow( function ($row) use (&$importCount){
$eachRow = $this->extractFieldsFromRow($row);
// Validate each Row of the csv file
$validatedData = Validator::make([
'first_name' => $eachRow['first_name'],
'last_name' => $eachRow['last_name'],
'email' => $eachRow['email'],
'password' => $eachRow['password'],
'extension' => $eachRow['extension'],
'user_type' => $eachRow['user_type'],
],[
'first_name' => 'required',
'last_name' => 'required',
'password' => 'required|max:255',
'user_type' => 'required|in:user,admin',
'email' => 'required|email|unique:account_users',
'extension' => ['required', 'numeric', Rule::unique('account_users', 'extension')
->where(function($query)
{return $query->where("account_id", $this->clientID);
})],
],);
if($validatedData->fails()){
$this->notify(['error','Oops something went wrong!']);
}else{
AccountUser::create([
'user_id' => Auth::user()->id,
'account_id' => $this->clientID,
'first_name' => $eachRow['first_name'],
'last_name' => $eachRow['last_name'],
'email' => $eachRow['email'],
'password' => $eachRow['password'],
'extension' => $eachRow['extension'],
'user_type' => $eachRow['user_type'],
]);
$importCount++;
}
});
$this->reset();
$this->emit('refreshExtensions');
if($importCount!=0) $this->notify(['success','Successfully Imported '.$importCount.' Extensions']);
}
public function guessWhichColumnsMapToWhichFields()
{
$guesses = [
'first_name' => ['first_name', 'name'],
'last_name' => ['last_name'],
'email' => ['email'],
'password' => ['password', 'pass'],
'extension' => ['extension', 'ext'],
'user_type' => ['user_type', 'user', 'type'],
];
foreach ($this->columns as $column) {
$match = collect($guesses)->search(fn($options) => in_array(strtolower($column), $options));
if ($match) $this->fieldColumnMap[$match] = $column;
}
}
public function extractFieldsFromRow($row)
{
$attributes = collect($this->fieldColumnMap)
->filter()
->mapWithKeys(function($heading, $field) use ($row) {
return [$field => $row[$heading]];
})
->toArray();
return $attributes;
}
public function downloadTemplate()
{
$filename = 'extensions_template.xls';
$path = public_path('files/' . $filename);
return response()->download($path, $filename, [
'Content-Type' => 'application/vnd.ms-excel',
'Content-Disposition' => 'inline; filename="' . $filename . '"'
]);
}
}
If you get mixed content problem it is mostly about you fetching the assets or resources from different http scheme. Here you are using HTTP to fetch data in HTTPS site. Change all the links to have HTTPS link.
If you want to force all the routes to use https you can achieve this by using following code.
if(env('APP_ENV', 'production') == 'production') { // use https only if env is production
\URL::forceScheme('https')
}
The above should solve your problem as all contents now will load from https.
i have a problem this controller is not working how can i do? should send mutiple emails how do i solve?
I don't know how to handle it
function submit(Request $request) {
$this->validate($request, [
'email' => 'required|email',
'file' => 'mimes:pdf,doc,docx'
]);
$data = array(
'name' => $request->name,
'cognome' => $request->cognome,
'luogo' => $request->luogo,
'date' => $request->date,
'telefono' => $request->telefono,
'email' => $request->email,
'citta' => $request->citta,
'provincia' => $request->provincia,
'studio' => $request->studio,
'lingua' => $request->lingua,
'livello' => $request->livello,
'lingua2' => $request->lingua2,
'livello2' => $request->livello2,
'file' => $request->file,
'agree' => $request->agree
);
Mail::send('mail', $data, function($message) use ($request,$data){
$message->to('luis#gmail.com', 'luis')->subject('Send mail ' . $request->name);
$message->from($request->email, $request->name);
if($request->hasFile('file')){
$message->attach($request->file('file')->getRealPath(), array(
'as' => $request->file('file')->getClientOriginalName(),
'mime' => $request->file('file')->getMimeType())
);
}
});
Session::flash('success', 'Mail spedita con sucesso');
}
I wish I could solve the problem
any advice? on how to do it?
I have the following in my view:
Pay with PayPal
Defined the route:
Route::get('pay-with-paypal', 'CheckoutController#payWithPaypal')->name('payment.paypal');
My CheckoutController looks like the one below:
use Srmklive\PayPal\Services\ExpressCheckout;
class CheckoutController extends Controller
{
public function payWithPaypal(){
$provider = new ExpressCheckout;
$data = [];
$data['items'] = [
[
'name' => 'Product 1',
'price' => 9.99,
'qty' => 1
],
[
'name' => 'Product 2',
'price' => 4.99,
'qty' => 2
]
];
$data['invoice_id'] = 1;
$data['invoice_description'] = "Order #{$data['invoice_id']} Invoice";
$data['return_url'] = url('/');
$data['cancel_url'] = url('/');
$total = 0;
foreach($data['items'] as $item) {
$total += $item['price']*$item['qty'];
}
$data['total'] = $total;
$response = $provider->setExpressCheckout($data);
// This will redirect user to PayPal
return redirect($response['paypal_link']);
}
}
My config looks like this:
return [
'mode' => 'sandbox', // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used.
'sandbox' => [
'username' => env('PAYPAL_SANDBOX_API_USERNAME', ''),
'password' => env('PAYPAL_SANDBOX_API_PASSWORD', ''),
'secret' => env('PAYPAL_SANDBOX_API_SECRET', ''),
'certificate' => env('PAYPAL_SANDBOX_API_CERTIFICATE', ''),
'app_id' => 'APP-80W284485P519543T', // Used for testing Adaptive Payments API in sandbox mode
],
'live' => [
'username' => env('PAYPAL_LIVE_API_USERNAME', ''),
'password' => env('PAYPAL_LIVE_API_PASSWORD', ''),
'secret' => env('PAYPAL_LIVE_API_SECRET', ''),
'certificate' => env('PAYPAL_LIVE_API_CERTIFICATE', ''),
'app_id' => '', // Used for Adaptive Payments API
],
'payment_action' => 'Sale', // Can only be 'Sale', 'Authorization' or 'Order'
'currency' => 'USD',
'billing_type' => 'MerchantInitiatedBilling',
'notify_url' => '', // Change this accordingly for your application.
'locale' => '', // force gateway language i.e. it_IT, es_ES, en_US ... (for express checkout only)
'validate_ssl' => true, // Validate SSL when creating api client.
];
My .env is also configured:
PAYPAL_SANDBOX_API_USERNAME=example-facilitator_api1.hotmail.com
PAYPAL_SANDBOX_API_PASSWORD=SLU2YLP4B
PAYPAL_SANDBOX_API_SECRET=TF3K8CtWTEmAcRu40.XWAihLRko
PAYPAL_SANDBOX_API_CERTIFICATE=
When I click on the link "Pay with PayPal", nothing happens. Anything I could have possibly done wrong?
Reference: https://github.com/srmklive/laravel-paypal
I created a form that when I submit I get an email. I've used mailtrap and gmail and both of them worked, but when I tried to use my own server email I don't get the email. I know that the code works because I've used it before.
I don't know if this played a roll in why it isn't working anymore but I had to reinstall windows on my laptop and reinstall xampp. I also had to change my password that I was using for my server email.
My .env
MAIL_DRIVER=smtp
MAIL_HOST=lin01.hkdns.co.za
MAIL_PORT=587
MAIL_USERNAME=info#myserver.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=
my mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info#myserver.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
My UsersController store method
public function store()
{
$users = new User();
$input = Input::all();
$validation = Validator::make($input, User::$rules);
if($validation->fails()){
return redirect()->route('admin.users.create')
->withInput()
->withErrors($validation)
->with('message', 'There were validation errors');
}
if($validation->passes()){
$users->name = Input::get('name');
$users->email = Input::get('email');
$users->image = Input::get('image');
$password = $users->generatePassword();
$users->password = bcrypt($password);
$data = array(
'name' => Input::get('name'),
'email' => Input::get('email'),
'password' => $password,
);
Mail::send('templates::emails.login', $data, function($message){
$message->to(Input::get('email'), Input::get('name'))->subject('Your login details');
});
$users->save();
$users = User::all();
return view('users::admin.index', compact('users'));
}
}
Also no errors show up in my storage/logs