Consider this sample of code that takes an array of addresses and sends each of them an email using the mailables feature.
//In my controller
$email = new EmailToWinners($sender_name, $letter);
foreach ($recipients as $recipient){
Mail::to($recipient)->send($email);
}
//In my App\Mail\EmailToWinner
public function build()
{
return $this->view('emails.winner-email');
}
The emails all get sent fine but when I was testing this I noticed, it's stacking the emails up.
So I get this in the logs.
[2017-02-16 15:58:59] local.DEBUG: Message-ID: <250443348fee18f568f4f263153d5101#testing.dev>
Date: Thu, 16 Feb 2017 15:58:59 +0000
Subject: Email To Winner
From: Example Dev <example#me.dev>
To: 1#example.com
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
[2017-02-16 15:58:59] local.DEBUG: Message-ID: <1b5f39ef0cc17d4d8573019f3d5ec808#testing.dev>
Date: Thu, 16 Feb 2017 15:58:59 +0000
Subject: Email To Winner
From: Example Dev <example#me.dev>
To: 1#example.com, 2#example.com
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
[2017-02-16 15:58:59] local.DEBUG: Message-ID: <ddf6c62a7f881f9381693435b48ef5a3#testing.dev>
Date: Thu, 16 Feb 2017 15:58:59 +0000
Subject: Email To Winner
From: Example Dev <example#me.dev>
To: 1#example.com, 2#example.com, 3#example.com
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
If you look at the emails. The first email shows to
1#example.com
The second shows to
1#example.com, 2#example.com
The third shows 1#example.com, 2#example.com, 3#example.com
So the first person gets 3 emails.
What am I doing wrong?
You can pass to to method a collection of users:
Mail::to($recipients)->send(new EmailToWinners());
From Lavavel Mail Docs:
The to method accepts an email address, a user instance, or a collection of users. If you pass an object or collection of objects, the mailer will automatically use their email and name properties when setting the email recipients, so make sure these attributes are available on your objects
I think you need to make a new email object for each recipient like this.
foreach ($recipients as $recipient){
Mail::to('$recipient')->send(new EmailToWinners($sender_name, $letter));
}
Related
I've spent some time trying to fix the elastic search bulk upload warning:
Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header
My request is below:
POST http://elasticserver/_bulk HTTP/1.1
Authorization: xxx
Content-Type: application/x-ndjson; charset=utf-8
Host: elasticserver
Content-Length: 8559
... new line delimited json content ...
And my valid response with 200 status is below:
HTTP/1.1 200 OK
Warning: 299 Elasticsearch-5.5.1-19c13d0 "Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header." "Mon, 14 Aug 2017 00:46:21 GMT"
content-type: application/json; charset=UTF-8
content-length: 4183
{"took":5538,"errors":false,...}
By experimenting I discovered that the issue is in content type charset definition Content-Type: application/x-ndjson; charset=utf-8 and if I change it to Content-Type: application/x-ndjson I get no warning.
Is it an elastic search issue or I'm forming the request incorrectly?
The official documentation explicitly states that
When sending requests to this endpoint the Content-Type header should be set to application/x-ndjson.
The RestController source code also shows that they are ignoring the charset:
final String lowercaseMediaType = restRequest.header("Content-Type").toLowerCase(Locale.ROOT);
// we also support newline delimited JSON: http://specs.okfnlabs.org/ndjson/
if (lowercaseMediaType.equals("application/x-ndjson")) {
restRequest.setXContentType(XContentType.JSON);
return true;
}
I'm trying to change PURGE response headers in Varnish4
HTTP/1.1 200 Purged
Content-Type: text/html; charset=utf-8
Date: Fri, 02 Sep 2016 19:57:56 GMT
Retry-After: 5
Server: Varnish
X-Varnish: 163921
Content-Length: 241
Connection: keep-alive
I have modified "Server: Varnish" in vcl_recv, vcl_deliver. Which seems to be working with any other request except for PURGE.
I need to change Server header or at least add a custom response header
I can't find any documentation about it so I was wondering if anyone done it before or it is a hardcoded option.
You need to override the built-in synthetic response generated by Varnish when purging objects. This can be trivially implemented using some extra VCL:
...
sub vcl_purge {
return (synth(700, "Purged"));
}
sub vcl_synth {
if (resp.status == 700) {
set resp.status = 200;
set resp.http.Server = "ACME";
}
}
If I go and unlock an achievement in game, and then run a reset, after running through the OAuth process for my user, posting to https://www.googleapis.com/games/v1management/achievements/reset, I receive a correct response,
{
"kind": "gamesManagement#achievementResetAllResponse",
"results": [
{
"definitionId": "CgkIh9rSofwUEAIQAQ",
"kind": "gamesManagement#achievementResetResponse",
"updateOccurred": true,
"currentState": "REVEALED"
}
]
}
If I post to https://www.googleapis.com/games/v1management/achievements/reset again, again I get a successful empty list response, as is expected,
{
"kind": "gamesManagement#achievementResetAllResponse",
"results": []
}
But when I go back into the game, check my achievements, it still shows that I have that achievement. No matter if I log out, log in, restart the app, makes no difference, I still have that achievement,
Even if I post the full reset, https://www.googleapis.com/games/v1management/achievements/resetAllForAllPlayers, I get the successful, no body response,
HTTP/1.1 204 No Content
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Vary: Origin,X-Origin
Server: GSE
Etag: "aHcpPO1q3J7BuZyftdPIkrurI0I/vyGp6PvFo4RvsFtPoIWeCReyIC8"
Pragma: no-cache
Cache-control: no-cache, no-store, max-age=0, must-revalidate
Date: Tue, 06 Oct 2015 15:14:31 GMT
I'm having a problem with some emails not being delivered with some ISP email address
Common email example reported by users : "xx#free.fr", "#bellsouth.net"
I don't really have a way to "test" why they don't get the emails. I told them to verify spam folder and they aren't there.. I have test account for popular email service "gmail, hotmail" and they work fine.
The emails I'm sending are common emails from my domain website (registration, confirm account, forgot password). I don't send any bulk email. I'm using goDaddy as hosting service.
I have set up SPF on my domain, and the email are sent with PHP(codeIgniter) - See bottom for how the mail is sent with code
Here is an example of mail that I sent that is blocked by theses ISP:
Delivered-To: tdfdestgmfdsailmaxmt123okdddf3#gmail.com
Received: by 10.112.159.166 with SMTP id xd6csp1482168lbb;
Wed, 17 Dec 2014 10:27:57 -0800 (PST)
X-Received: by 10.50.61.238 with SMTP id t14mr9680303igr.34.1418840877015;
Wed, 17 Dec 2014 10:27:57 -0800 (PST)
Return-Path: <admin#maximumtrainer.com>
Received: from p3nlsmtpcp01-03.prod.phx3.secureserver.net (p3nlsmtpcp01-03.prod.phx3.secureserver.net. [184.168.200.142])
by mx.google.com with ESMTP id hh16si4059486icb.62.2014.12.17.10.27.56
for <tdfdestgmfdsailmaxmt123okdddf3#gmail.com>;
Wed, 17 Dec 2014 10:27:56 -0800 (PST)
Received-SPF: pass (google.com: domain of admin#maximumtrainer.com designates 184.168.200.142 as permitted sender) client-ip=184.168.200.142;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of admin#maximumtrainer.com designates 184.168.200.142 as permitted sender) smtp.mail=admin#maximumtrainer.com
Received: from p3plcpnl0063.prod.phx3.secureserver.net ([184.168.200.112])
by p3nlsmtpcp01-03.prod.phx3.secureserver.net with : CPANEL :
id UiR51p01s2S0Aj401iR5yP; Wed, 17 Dec 2014 11:25:05 -0700
Received: from p3plcpnl0063.prod.phx3.secureserver.net ([184.168.200.112]:34603 helo=maximumtrainer.com)
by p3plcpnl0063.prod.phx3.secureserver.net with esmtpa (Exim 4.84)
(envelope-from <admin#maximumtrainer.com>)
id 1Y1JKF-0001bp-W0
for tdfdestgmfdsailmaxmt123okdddf3#gmail.com; Wed, 17 Dec 2014 11:27:56 -0700
User-Agent: CodeIgniter
Date: Wed, 17 Dec 2014 18:27:55 +0000
From: "Maximum Trainer" <admin#maximumtrainer.com>
To: tdfdestgmfdsailmaxmt123okdddf3#gmail.com
Subject: =?utf-8?Q?Bienvenue?=
Reply-To: "admin#maximumtrainer.com" <admin#maximumtrainer.com>
X-Sender: admin#maximumtrainer.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5491cb2be1fa8#maximumtrainer.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - p3plcpnl0063.prod.phx3.secureserver.net
X-AntiAbuse: Original Domain - gmail.com
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - maximumtrainer.com
X-Get-Message-Sender-Via: p3plcpnl0063.prod.phx3.secureserver.net: authenticated_id: admin#maximumtrainer.com
X-Source:
X-Source-Args:
X-Source-Dir:
CodeIgniter sender function:
function send_confirmation_mail($email, $first_name, $confirm_code) {
$CI =& get_instance();
$CI->load->library('email'); // load library
$CI->email->from ( 'admin#maximumtrainer.com', 'Maximum Trainer' );
$CI->email->to ( $email );
$CI->email->subject ( lang('email_activate_title') );
$link = base_url(). index_page(). lang('url_confirm_user'). "/". $confirm_code;
$message = lang('email_hello'). $first_name. ", \r\n".
lang('email_activate_thank_you'). "\r\n\r\n".
lang('email_activate_click_link'). "\r\n".
$link. "\r\n\r\n".
lang('email_activate_farewwell'). "\r\n".
lang('email_linkMT');
$CI->email->message( $message );
if ( ! $CI->email->send()) {
$CI->messages->add("error send_confirmation_mail", "error");
return false;
}
return true;
}
Server config :
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
#$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'p3plcpnl0063.prod.phx3.secureserver.net';
$config['smtp_user'] = 'yyyyyy#maximumtrainer.com';
$config['smtp_pass'] = 'xxxxxxx';
$config['smtp_port'] = 25; #465 to test doesnt seem to work
$config['smtp_timeout'] = 5;
$config['wordwrap'] = FALSE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'text';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;
Are there any services to diagnose what could be the cause of the problem? I can't register for free with these email providers in order to test.
I testing Email Migration API V2 with google client api for ruby version 0.7.1
For multipart upload I always getting this response from server:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "Backend Error"
}
],
"code": 503,
"message": "Backend Error"
}
}
Here is my code:
client = Google::APIClient.new(
:application_name => 'My app',
:application_version => '1.1.0'
)
#auth code skipped
migration = client.discovered_api('admin', 'email_migration_v2')
file = {"isInbox" => true}
mail = StringIO.new "Date: Wed, 03 Jan 2013 02:56:03 -0800
From: admin#example.org
To: liz#example.com
Subject: Hello World!
MIME-Version: 1.0
Content-Type: text/html; charset=windows-1252
Content-transfer-encoding: 8bit
And I think to myself... What a wonderful world!"
media = Google::APIClient::UploadIO.new(mail, 'message/rfc822')
client.execute!(:api_method=> migration.mail.insert,
:media => media,
:body_object => file,
parameters: {
'userKey' => "name#domain.com",
'uploadType' => 'multipart',
})
Some logs info
DEBUG 18:58:13 rails [pid=6311]: Google::APIClient::Request Sending API request post https://www.googleapis.com/upload/email/v2/users/name#domain.com/mail?uploadType=multipart {"User-Agent"=>"My app/1.1.0 google-api-ruby-client/0.7.1 Mac OS X/10.9.4\n (gzip)", "Content-Type"=>"multipart/related;boundary=-----------RubyApiMultipartPost", "Content-Length"=>"682", "Accept-Encoding"=>"gzip", "Authorization"=>"Bearer xxxxx", "Cache-Control"=>"no-store"}
POST BODY:
DEBUG 18:58:13 rails [pid=6311]: -------------RubyApiMultipartPost
Content-Disposition: form-data; name=""; filename="file.json"
Content-Length: 16
Content-Type: application/json
Content-Transfer-Encoding: binary
{"isInbox":true}
-------------RubyApiMultipartPost
Content-Disposition: form-data; name=""; filename="local.path"
Content-Length: 249
Content-Type: message/rfc822
Content-Transfer-Encoding: binary
Date: Wed, 03 Jan 2013 02:56:03 -0800
From: admin#example.org
To: liz#example.com
Subject: Hello World!
MIME-Version: 1.0
Content-Type: text/html; charset=windows-1252
Content-transfer-encoding: 8bit
And I think to myself... What a wonderful world!
-------------RubyApiMultipartPost--
Please help me understand why google responds with 503. And how I can resolve it.
I am sure that I didn't reach API quota.
Update 1:
Looks like Content-Disposition header is the reason of 503 error, Because without it upload works fine!