Queue email receiver email address issue laravel 4.2 - php

I am working in laravel 4.2 version and sending email for marketing purpose. But the problem is that when i send email to many users then all the users can view the email addresses of other users.
I am sending email using laravel queue method and here is my working code
$emails[] = 'someonea#gmail.com';
$emails[] = 'someoneb#gmail.com';
$emails[] = 'someonec#gmail.com';
$emails[] = 'someoned#gmail.com';
$emails[] = 'someonee#gmail.com';
if(!empty($emails)){
$data['content'] = $message;
$admin_email = UserHelper::$driver['admin_email'];
$site_title = UserHelper::$driver['site_title'];
Mail::queue('emails.market',$data,function($mail)use($emails,$subject,$data){
$mail->to($emails);
$mail->subject($subject);
$mail->from($emails);
});
}
when i receive an email then i am also able to see the email all other users in to of inbox.
Please help to resolve this issue.
Thanks in advance

You can try bcc to send the same email to other users. When you use BCC, any recipients on the Bcc line of an email are not visible to others on the email.
Mail::queue('emails.market',$data,function($mail)use($emails,$subject,$data){
$mail->to($firstEmailAddredd);
$mail->to($restAllEmailAddredd);
$mail->subject($subject);
$mail->from($emails);
});
Not tested this thing, but sure that this will help you!

Related

Laravel send email using mail::to without viewing other recipients

I have an array of recipients $this->recipients and I want to send an email to all recipients without showing each other emails.
Currently, it shows all the recipients in an email.
if (count($this->recipients) > 1) {
Mail::bcc($this->recipients)
->send(new EmailNotificationMailable($this->notificationRequest));
} else {
Mail::to($this->recipients)
->send(new EmailNotificationMailable($this->notificationRequest));
}
I tried this code but when I send with Mail::bcc the To of email is empty.
Please give the working solution for this. I don't want to loop recipients array
You need to loop through the recipients collection:
if(count($this->recipients) > 1)
{
$this->recipients->each(function($recipient)
{
Mail::to(recipient)->bcc($this->recipients)->send(new EmailNotificationMailable($this->notificationRequest));
}
}else{
Mail::to($this->recipients)->send(new EmailNotificationMailable($this->notificationRequest));
}
Use something like this:
Mail::to(array_pop($this->recipients))->bcc($this->recipients)
This will set the last entry in the recipients array as the mail receiver and every other addresses will be included via BCC.

Can't send BCC emails through Mandrill (via Laravel)

I am unable to send emails to users through the Mandrill plugin in Laravel using BCC. I can send emails "to" the addresses, as follows:
Mail::send('emails.coach_invite', $data, function($message) use ($coach, $emails) {
foreach ($emails as $email) {
$message->to($email);
}
$message->subject($coach->first_name.' '.$coach->last_name.' has invited you to try Nudge!');
});
This works just fine. However, if I try to BCC the same users:
Mail::send('emails.coach_invite', $data, function($message) use ($coach, $emails) {
foreach ($emails as $email) {
$message->bcc($email);
}
$message->subject($coach->first_name.' '.$coach->last_name.' has invited you to try Nudge!');
});
Nothing happens. Mandrill doesn't even acknowledge that the request came in. Any ideas why this isn't working? If it helps, here are my raw email headers:
Message-ID: <688aa904847640c9ff694521ccb85ee5#nudge-api.app>
Date: Thu, 07 Aug 2014 11:15:35 -0400
Subject: Coach McTest would like to be your Coach on Nudge!
From: Nudge Info <info#nudgeyourself.com>
Bcc: Chris Garson <chris#nudgeyourself.com>
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
I can confirm that sending emails to Bcc users doesn't really work as expected in Mandrill.
The easiest way to send what you want (single email to multiple addresses, with each addressee only seeing their own name in the delivery list), is to set the X-MC-PreserveRecipients header to false and then just send the email using the To field rather than Bcc.
This will send the email as if it were sent to each recipient individually, rather than as a group email - nobody will know who else was sent the email.
Here's how to do it in Laravel using your example:
Mail::send('emails.coach_invite', $data, function($message) use ($coach, $emails) {
foreach ($emails as $email) {
$message->to($email);
}
$message->subject($coach->first_name.' '.$coach->last_name.' has invited you to try Nudge!');
$headers = $message->getHeaders();
$headers->addTextHeader('X-MC-PreserveRecipients', 'false');
});
Note that I'm using $message->to() to address the email and then adding the X-MC-PreserveRecipients header which is set to false.
I worked for me both CC and BCC way.
Ref document: https://mandrill.zendesk.com/hc/en-us/articles/205582117-Using-SMTP-Headers-to-customize-your-messages
Search keyword: X-MC-PreserveRecipients
$headers = $message->getHeaders();
$headers->addTextHeader('X-MC-PreserveRecipients', true);
Using the X-MC-BccAddress should do the job. You can only use one bcc address though.
See https://mandrill.zendesk.com/hc/en-us/articles/205582117-Using-SMTP-Headers-to-customize-your-messages

Mail Multiple users with php

I normally mail single user on php but what I dont know if its possible to fetch all emails from the users table and bundle it in one variable ($to) and then mail it together with
mail($to, $subject, $message, $headers);
Can anyone help me with the syntax on how to mail multiple users? I am new to php and mysqli.
Thanks.
PHP send mail to multiple email addresses
$recipients = array(
"youremailaddress#yourdomain.com",
// more emails
);
$email_to = implode(',', $recipients); // your email address
$email_subject = "Contact Form Message"; // email subject line
$thankyou = "thankyou.htm"; // thank you page
mail($email_to, $email_subject, $thankyou);
Note that you can use a custom message in place of $thankyou if you just want a standard message instead of html.

PHP Mailer --- Reply-to: --- Return-path --- SetFrom

I am sending mail via PHP Mailer. http://phpmailer.worxware.com/
I want to be able to set the From to one emailand the REPLY-TO to another email and the RETURN-PATH to yet another.
Mainly.. I want the bounced emails to go to something like BOUNCEDemails#bademail.com
I was hoping the RETURN PATH could do this.
And if a user who gets the email I don't want them to see its from BOUNCEDemails etc.. to I want to give them an option to reply to a real email address.
I need the bounced emails tho to go to a seperate email because I don't want the REPLY TO to get many bad emails. etc..
HERE IS WHAT I HAVE: Does Not work
$mail->AddAddress('ed#RealEmail.org', 'John Doe');
$mail->AddReplyTo('replytoMe#email.com', 'Reply to email');
$mail->SetFrom('mailbox#email.com', 'From Name and Email');
$mail->AddCustomHeader('Return-path: BOUNCEDemails#bademail.com');
The code above replies to SetFrom and sends all bounces to SetFrom. Any ideas how to separate the two? Thanks
the correct way to set this (as of july 2013) is by using:
$mail->ReturnPath='bounce_here#domain.com';
the phpmailer source contains the following, which is fairly self explanatory:
if ($this->ReturnPath) {
$result .= $this->HeaderLine('Return-Path', '<'.trim($this->ReturnPath).'>');
} elseif ($this->Sender == '') {
$result .= $this->HeaderLine('Return-Path', '<'.trim($this->From).'>');
} else {
$result .= $this->HeaderLine('Return-Path', '<'.trim($this->Sender).'>');
}
You may use
$mail->AddReplyTo('name#yourdomain.com', 'First Last');
$mail->AddReplyTo('replytoMe#email.com', 'Reply to email');
$mail->AddAddress('ed#RealEmail.org', 'John Doe');
Notice the order! AddReplyTo has to be BEFORE AddAddress!!!

How can I add HTML formatting to 'Swift Mail tutorial based' PHP email?

I have developed a competition page for a client, and they wish for the email the customer receives be more than simply text. The tutorial I used only provided simple text, within the 'send body message'. I am required to add html to thank the customer for entering, with introducing images to this email.
The code is:
//send the welcome letter
function send_email($info){
//format each email
$body = format_email($info,'html');
$body_plain_txt = format_email($info,'txt');
//setup the mailer
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message ->setSubject('Thanks for entering the competition');
$message ->setFrom(array('info#examplemail.com' => 'FromEmailExample'));
$message ->setTo(array($info['email'] => $info['name']));
$message ->setBody('Thanks for entering the competition, we will be in touch if you are a lucky winner.');
$result = $mailer->send($message);
return $result;
}
This function.php sheet is working and the customer is recieving their email ok, I just need to change the
('Thanks for entering the competition,
we will be in touch if you are a lucky
winner.')
to have HTML instead...
Please, if you can, provide me with an example of how I can integrate HTML into this function.
You can also just add 'text/html' to setBody (ref):
->setBody($this->renderView('YouBundleName:Default:email.html.twig'), 'text/html');
$message = Swift_Message::newInstance();
$message->setContentType('text=html');
Will the same text remain or should it be styled somehow?
Editing your emails in html requires inline css styles eg:
('<p style="font-size:1.2em; color:#f0f0f0;">Thanks for entering the competition, we will be in touch if you are a lucky winner.</p>')
if you need a table just add:
('<table style="font-size:1.2em; color:#f0f0f0;"><tr><td>Thanks for entering the competition, we will be in touch if you are a lucky winner.</td></tr></table>')
or to make it more simpler
$message_body'
<table style="font-size:1.2em; color:#f0f0f0;">
<tr>
<td>Thanks for entering the competition, we will be in touch if you are a lucky winner.</td>
</tr>
</table>
';
$message ->setBody($message_body);
I know that when I need to send html emails I need to set the content-type to html which I believe you did on the following line
$body = format_email($info,'html');
I hope this is what you were looking for. if not let me know

Categories