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

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

Related

PHPMailer no longer processing multipart email correctly

I've been using a PHPMailer script for years sending emails to my group. Everything was working great up until last week. Now when I send an email the multi-part is fully displayed as plain text. Here is my PHP script:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '/fullpath/public_html/tmp/PHPmailer.php';
require '/fullpath/public_html/tmp/SMTP.php';
require '/fullpath/public_html/tmp/Exception.php';
$body = $_POST['msgText'];
$mail = new PHPMailer();
$mail->setFrom('MY WEB SITE EMAIL', 'ME');
$mail->addReplyTo('MY EMAIL', 'ME');
$mail->addAddress('MY EMAIL', 'ME');
$mail->Subject = $_POST['subjectText'];
$mail->isHTML(true);
$mail->SMTPDebug = 2;
$mail->Body = $body;
$mail->CharSet = 'UTF-8';
$a = $_POST['toText'];
// For output display
echo "<!DOCTYPE html>\n<html lang=en><head><title>My Test PHP Mailer</title></head>\n<body>\n<h1>My Test PHP Mailer</h1>\n<h4>Sending Emails to:</h4>\n<ul>";
foreach ($mail->parseAddresses($a) as $address) {
$mail->addBCC($address['address'], $address['name']); // for release
// $mail->addAddress($address['address'], $address['name']); // for testing
echo "<li>Name: " . $address['name'] . " - address: [" . $address['address'] . "]</li>\n";
}
echo "</ul>\n";
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
echo "<br>" . $_POST['toText'];
} else {
echo "<form><textarea name=ta>" . $body . "'></textarea></form>";
}
echo "<p><a href='index.php'>Back to index.php</a></p>\n</body>\n</html>";
?>
And my email is showing up like this:
This is a multi-part message in MIME format.
--b1_5S1Pr6ILOHSPuOiGgJGQzPfIPsBjnsOmX6MAuoro
Content-Type: text/plain; charset=us-ascii
Good luck to all, and thanks for participating,
--b1_5S1Pr6ILOHSPuOiGgJGQzPfIPsBjnsOmX6MAuoro
Content-Type: text/html; charset=us-ascii
<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></HEAD>
<BODY bgColor="#ffffff">
<div style="max-width:800px;border:1px solid #666666; padding:9px; background-color:white;">
<DIV><FONT face="Arial" color="#000080" size="6"><B><I>NFL
<FONT color="#C80000">Challenge</FONT> 2022</I></B></FONT></DIV>
<DIV><FONT face="Arial, Helvetica" color="#ff0000" size="4"><B>Hey Sportsfans,</B></FONT></DIV>
<br>
<DIV><FONT face="Arial" size="2">Good luck to all, and thanks for participating,</FONT></DIV>
<br>
</DIV></div>
</BODY>
</HTML>
--b1_5S1Pr6ILOHSPuOiGgJGQzPfIPsBjnsOmX6MAuoro--
I haven't made any changes in the last week. Why would the emails be sent as simply text and not do the multi-part encoding? This output is the same for all mail clients.
I have searched the internet for the last week and can't find anything that helps. I did update to the latest version of PHPMailer to see if that would fix the problem, but it still remains. I want the email to be sent as HTML and not have the raw details going out to all my friends.
Any suggestions, opinions or dumb looks appreciated.
==============[ UPDATE ]=================
I was asked to specify more details on my problem. When I tried initially, Stackoverflow gave me an error that this was a spam submission. So I'm going to try again and redact some details to hopefully avoid that error.
First - the email is being sent using PHPMailer 6.1.1
Second - the email clients receiving the emails that I have been able to test are: Gmail, Outlook, and Yahoo Mail.
Third - I was asked to share the raw source of the email (this is where I hope I can avoid the 'spam' error).
This is the last working email I sent, as reported from Gmail "show original":
Subject: NFL Challenge 2022 - Week 18 Reminder
X-PHP-Script: xxxxxxxxxxxx/file.php for 162.252.247.224
X-PHP-Originating-Script: 1002:PHPmailer.php
Date: Fri, 6 Jan 2023 01:02:03 +0000
From: NFL Challenge <me#myserver>
Message-ID: <GdssaiyhOGwE5lgWdOnRMleJbhKIfeZQPc4TpJB74#www.starbase47.com>
X-Mailer: PHPMailer 6.1.1 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="b1_GdssaiyhOGwE5lgWdOnRMleJbhKIfeZQPc4TpJB74"
Content-Transfer-Encoding: 8bit
X-CMAE-Envelope: MS4xfNLwjf/lI+ECbHq2uNTaPo2pDBlT0LgWHZfm+1mtCGh1qLdFoViGjgSHemmT9C8buRCOrt1A4pAvnGulYNkPiO6cJBSDRVv2s9yqB3tUM/GOH02Idbpt 4uA8x2WkhDDGrE1gBk+cE3ZeAWqXwfQWDQznYq5N7InVD9s4UlutNmMlACjSidhnEIrzVJHFZsR3gvGOSiEZDf8Xg4jjk51comuqnF4hLvF9slMWKexfPYfp 6Xxsb7BqWoHfbmSTB0WrMR6wzG3e0ybFGe3HDiMIPPCsHfCHUzaLjXMSfUCI8xcbnScfTz9t/00yLtSwLj4nu+sganzgBI433vpvFj28Aw7bDlm4K0iERspz shEaDRpZwHKD44xwCTSsa/zjvrXAdsOo39EuWLtn25QSOT3QYuEKmpe4M1mMGS6BH/oP3rxUGu89rDzc7fBcav7MtnNLI7Wz2kWAnBvuyrZWhKM/vBzLUUd/ uWtz/nhTNzzItSy1rm8ObR+cm6RuWil0uilXF9nF/gg5TzFOixzNgTuvexbclXCl198ACnro7gQfxMM47NeRuZkhQUjjOuhm+k0TeJyRKWD7S1ujA3qfndH/ 8LI=
--b1_GdssaiyhOGwE5lgWdOnRMleJbhKIfeZQPc4TpJB74
Content-Type: text/plain; charset=us-ascii
NFL
Challenge 2022
Hey Sportsfans, ...
This is the source of the email that didn't format correctly, again from Gmail "show source".
Subject: NFL Challenge 2022 - Playoffs Test
X-PHP-Script: www.starbase47.com/mytest_mail.php for 162.252.247.224 X-PHP-Originating-Script: 1002:PHPmailer.php
Date: Thu, 12 Jan 2023 21:33:09 +0000 From: NFL Challenge <me#myserver> Message-ID: <5S1Pr6ILOHSPuOiGgJGQzPfIPsBjnsOmX6MAuoro#www.starbase47.com> X-Mailer: PHPMailer 6.1.1 (https://github.com/PHPMailer/PHPMailer) MIME-Version: 1.0 Content-Type: multipart/alternative;
boundary="b1_5S1Pr6ILOHSPuOiGgJGQzPfIPsBjnsOmX6MAuoro" Content-Transfer-Encoding: 8bit
Message-Id: <E1pG5C9-0006pY-1D#192.222.167.72.host.secureserver.net>
From: me#myserver
X-CMAE-Envelope: MS4xfI/De/t+kmwbb6eY2xWVi89UxsAiJ5qMwBEnzqpJBSwnrpHKLYrLpRjMnFUNxqZVwAckeapMXSEzXsK71DSiMO5WP0VZxM0iNr0qMiD/lOxS2Sp5+Vb0 4nUe/KgwmKZcA8v6BUI5N0fFqt5Ha2nrzlg4ouBiPrZTTYgrTQ+UQoHWyWWl/LWrhDX5AUYdRYL/DI0Q7u5H+LjjhdKhAOdTeKAPsa+EEkVMxWbX/z27TF2m jzATQVQbCe7u4en0+gEgDg==
This is a multi-part message in MIME format.
--b1_5S1Pr6ILOHSPuOiGgJGQzPfIPsBjnsOmX6MAuoro
Content-Type: text/plain; charset=us-ascii
NFL
Challenge 2022
Hey Sportsfans, ...
If you need me to share more details (like from another client, or the raw PHPMailer code that I have on my server) please let me know.
Thank you in advance - Einstein47

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.

Queue email receiver email address issue laravel 4.2

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!

How to send large emails without spam?

I need to know what is best method to send multiple emails using php. It should not be stored in spam and also should send fast.
I already tried normal mail function in PHP. But it is not working well. Also tried using mail function within loop. Only few mails sent and some of them reached under spam folder.
My project is running at live server. And I am using free hosting service.
My Code:
<?php
include "initialize.php";
if($source_url!='http://kalaivanan.byethost18.com/uadmin/send_result.php')
{
echo "Access Denied";
}
else
{
$id=$_GET['id'];
$get_sem_period1=mysqli_query($con, "SELECT * FROM sem_period where id='$id' ");
$get_sem_period=mysqli_fetch_array($get_sem_period1);
$sem_period=$get_sem_period['sem_period'];
$rrr=mysqli_query($con, "SELECT * FROM results where sem_period='$sem_period' ");
$i=1;
while($row=mysqli_fetch_array($rrr))
{
$get_course=mysqli_query($con, "SELECT course,email FROM student_details where reg_no='$row[reg_no]' ");
$get_course1=mysqli_fetch_array($get_course);
$course_name=$get_course1['course'];
$to=$get_course1['email'];
$get_sub1=mysqli_query($con, "SELECT * from course_details where course_name='$course_name' ");
$get_sub=mysqli_fetch_array($get_sub1);
$sem_no=$row['sem_no'];
$subjects=$get_sub['sem'.$sem_no];
$new_subjects=explode(",",$subjects);
$new_marks=explode(",", $row['sem_mark']);
$echo_subject=null;
for($x=0;$x<sizeof($new_subjects);$x++)
{
if($new_marks[$x]>40)
{
$exam_result="Pass";
}
else
{
$exam_result="Fail";
}
$echo_subject .="<tr><td>".$new_subjects[$x].": ".$new_marks[$x]." - ".$exam_result."</td></tr>";
}
$errors='';
$myemail = 'MYEMAIL';
if( empty($errors))
{
$email_subject = "Enquiry Form: Your Results";
echo "Mail id is: ".$to;
echo $email_body = "<table border='1'>
</br> $sem_period Result Will be Announced: Check Your Marks </br> </br>
<tr>
<td> Register Number: ".$row['reg_no']. "</td>
</tr>
<tr>
<td> Course Name: ".$course_name. "</td>
</tr>
<tr>
<td> Semester: ".$sem_no. "</td>
</tr>
<tr>
<td>MARKS ARE:</td>
</tr>
<tr>
<td> ".$echo_subject." </td>
<td> </td>
</tr>
</table>
";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $myemail";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
echo "<script>alert('Mail Send Successfully');</script>";
}
$email_address="MYEMAIL";
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
}
}
?>
My Answer:
After 1 year, in my experience I learned that for sending large mails without Spam, we have to find good mail service provider.
You should consider using an email sending service, such as Amazons SES, or other marketing tools such as Emma, Mail chimp, sendgrid, mailjet, mandrill, etc.
Free hosts are very susceptible to getting blocked by email servers due to the very nature of use for spam.
This question is a matter of dispute for all the marketers. No one marketer is immune to be called a spammer. These are three main reasons which influence the email reputation:-
Technical setting.
Email content and design.
Reaction to your bulk emails.
A. Technical Settings
Your email must be in the correct format. To ensure the format email underwent you will have to perform SPF and DKIM checkout.
Use a special header in bulk emails for people to know what you send.
Don't forget to add unsubscribe link in an email and it is easy to see and have adequate size and font color.
A reputation of your IP address and domain must be high.
B. Email Content And Design
Avoid using spam words in your mail such as discount, income, money, check, and many more words.
Links that you used in your emails are extremely important. Never take a link from a suspicious resource. Otherwise, it may be fraud.
Your email must be in the plain text version.
C. Recipients’ reaction to your bulk emails
Every email must contain unsubscribe link for the recipient to unsubscribe but not mark as spam.
Name and address of the sender are familiar to the recipients.
The frequency of email sending:- Don't send emails every day. The optimal frequency is not more than once a week.
If you want to know the complete points on this then click here.
I written first time on this community, I hope this article will help you.
If I understood right, you are trying to send emails to multiple users. If so, then try with array & implode() like this below script to send multiple emails. Avoid spam is how you pass the scoring like frz3993 said in comment. And also based on your hosting service provider, the speed, performance factors, etc., measured.
Look that the formatting of this string must comply with RFC 2822 as per Standard.
<?php
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: Kalaivanan <kalai#domain.com>";
$headers[] = "Bcc: Alagu <alagu#domain2.com>";
$headers[] = "Reply-To: Recipient Name <office#domain3.com>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
$receivers = array('vanan#gmail.com', 'alagukan#gmail.com', 'mathi#gmail.com',.... );
mail(implode(',', $receivers), $subject, $message, $implode("\r\n", $headers));
?>
After few years, I learned many this regarding sending large emails. But the basic this I got from below link. This may be useful for you.

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!!!

Categories