服务器:数字海洋
Ubuntu 16.04
Laravel 5.8
我无法使用mailgun.com从laravel发送电子邮件
在Digital Ocean中,我在防火墙上打开了所有传出端口,在Digital Ocean中,我具有用于TXT和MX记录的正确DNS设置。我在域registar上拥有正确且经过验证的DNS记录,并且mailgun在所有域名上都带有绿色的选中标记
config / mail.php
return [
'driver' => 'mailgun',
'host' => 'smtp.mailgun.org',
'port' => 587,
'from' => [
'address' => 'orders@domain.com',
'name' => 'Company Name'
],
'encryption' => 'tls'),
'username' => 'orders@mg.domain.com',
'password' => 'xxxxd663hd02j727bb2eefd1ea38bbe0-58bc211a-670xxxx'
];
Run Code Online (Sandbox Code Playgroud)
config / services.php
'mailgun' => [
'domain' => 'https://api.mailgun.net/v3/mg.domain.com',
'secret' => 'xxxxehbe8v25g3374e5as3ff32a45995-39bc661a-4716xxxx',
],
Run Code Online (Sandbox Code Playgroud)
控制者
use Illuminate\Support\Facades\Mail;
$data = [
'email' => 'email@yahoo.com',
'name' => 'Bob Smith'
];
$body_data = [
'id' => '1234'
];
Mail::send('emails.shipped', $body_data, …Run Code Online (Sandbox Code Playgroud) 我正在使用Laravel 5.1,并希望有一个带有几行文本字段的表单及其相应的图像上传.
形成:
<div id="row">
<input name="description[]" type="text">
<input name="image[]" type="file">
</div>
<div id="row">
<input name="description[]" type="text">
<input name="image[]" type="file">
</div>
Run Code Online (Sandbox Code Playgroud)
控制器:
foreach($request->description as $key => $val){
if($val != null){
$data = new Finding;
$data->description = $val; //save description for each loop
$file = array('image' => Input::file('image'));
if (Input::file('image')->isValid()) {
$destinationPath = 'uploads';
$extension = Input::file('image')->getClientOriginalExtension();
$fileName = rand(1000,1000).'.'.$extension;
Input::file('image')->move($destinationPath, $fileName);
$path = Input::file('image')->getRealPath();
$data->image_location = $fileName[$key]; //save filename location to db
$data->save();
flash('success', 'Uploaded Successful');
return Redirect::to('/upload');
} else …Run Code Online (Sandbox Code Playgroud) 我试图仅获取产品表中的类别集合。我的类别表有 300 个项目。如果产品表中附加了类别,我只需要一个集合。$categories 集合应该只会产生大约 10 个类别,因为只有大约 10 个产品具有不同的category_ids
$products = DB::table('products')->groupBy('category_id')->get();
foreach($products as $product){
$categories[] = DB::table('categories')->where('id', '=', $product->category_id)->first();
}
$categories = collect($categories)->all();
Run Code Online (Sandbox Code Playgroud)
也许我会犯这个错误,应该使用不同的查询生成器方法?
最终结果 $categories 确实得到了我想要的结果,但在我的刀片中我收到“尝试获取非对象的属性”错误。
我正在使用 cURL 构建一个简单的 REST API 包,并希望捕获错误然后返回视图。如果我 dd($e) 我可以抛出错误,但如果我尝试返回一个视图,它只会继续执行 catch 函数之后的代码。PHP 不应该终止进程并直接进入登录视图吗?
try{
$response = Http::timeout(2)->asForm()->post('https://' . $this->ip_address, [
'username' => $this->username,
'password' => $this->password
]);
} catch(\Illuminate\Http\Client\ConnectionException $e) {
return view('auth.login');
}
Run Code Online (Sandbox Code Playgroud)
如果我遇到 cURL 超时异常,我现在只想返回登录页面。如果我输入一个伪造的IP地址,显然它会在2秒后超时,这就是我正在测试的。
使用 Laravel Http 客户端,如何捕获该错误并显示身份验证登录视图?
我花了5个小时才完成这项工作.我只是想提交一个表单并要求用jquery ui弹出窗口确认删除,当确认它进入表单提交并转到delete.php.
为简单起见,我已将其剥离了:
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/black-tie/jquery-ui.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-2.1.1.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#formDelete').submit(function(e){
e.preventDefault();
$('#dialog').dialog('open');
});
$('#dialog').dialog({
autoOpen: false,
modal: true,
buttons: {
"Confirm": function() {
$('#formDelete').submit();
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
});
</script>
</head>
<body>
<div id="dialog">
<p>Are you sure you want to delete?</p>
</div>
<form id="formDelete" name="formDelete" action="delete.php" method="POST" >
<input name="id" type="hidden" value="1">
<input name="submit" type="submit">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我点击是按钮,没有任何反应.我已经尝试将提交ID更改为与表单相同但读取只是循环所有内容.
使用 Laravel 的查询构建器示例可以将变量传递给此函数:
$someVariable = 1;
DB::table('users')
->where('name', '=', 'John')
->orWhere(function ($query) use ($someVariable) {
$query->where('votes', '>', $someVariable)
->where('title', '<>', 'Admin');
})
->get();
Run Code Online (Sandbox Code Playgroud)
该函数似乎无法访问自身之外的变量。我收到一个错误:未定义的变量:$someVariable