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

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

Related

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!

Multiple emails with unique content PHP mailer?

I want to send unique emails to multiple people (could be 1, could be 100) using PHPMailer.
$notifyemailscontent is an array that holds all the emails and names (again, could be 1 could be 100).
This below works, but I'm curious if there is a better way to do this. It seems to take a while even when there's only like 5 emails. Is there a quicker, more efficient way to do this type of thing? Or does it simply take this long if you're sending multiple emails?
/// Send notification email
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->setFrom('admin#mydomain.com', 'MyDomain');
$mail->addReplyTo('admin#mydomain.com', 'MyDomain');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "FYI, there's a new entry!";
foreach($notifyemailscontent as $email => $name) {
$mail->addAddress($email, $name);
$mail->Body = "Hi $name!<br><br>
We're just letting you know that there is a new entry. To see it, click the link below:<br><br>
<a style='background: blue; color: white;' href='http://myfulldomain'>the pool name</a>
";
$mail->AltBody = "";
$mail->send();
$mail->ClearAddresses();
}

PHPMailer - Sending to multiple address but unique content

I am building a quote system, the quote system sends out the quote to multiple people with a personalised message via email. I am using the following code to do so:
$mail = new PHPMailer();
$mail->AddReplyTo("myAddress#domain.com", "Company");
$mail->SetFrom('quotes#company.com', 'COMPANY');
// Set each of the recipients
$users = $quote->GetClients();
foreach($users as $user)
{
$mail->AddAddress($user["Email"], $user["Name"]);
}
$mail->Subject = "Hello" . $users[0]["Name"];
$body = "This is your personal Email";
$mail->MsgHTML($body);
$mail->Send();
The problem being is that, when I send this email, it sends to all the recipients that it should, but it includes all of the recipients names. Whereas, I just want to display for that particular person. I.e. If I get an email, it would be: "Hello Phorce, This is your Personal Email" but instead I get "Hello {user1} {user2} {user3}" and this is not what I want.
Is it possible to do what I am trying to do using PHPMailer?

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

Setting replyTo field in email

I have an SMTP question. I have created a PHP script to send out emails. The requirement is that I need to send email from 'email1#example.com' but I need replies to come to 'email2#example.com'
I have added email2#example.com in the reply-to header field. The only problem I am having is that when someone receives the email and clicks on the reply button, both email1#example.com and email2#example.com are being shown in the TO field.
Is there any way that I can have email1#example.com removed from the TO field and only show the email address that was specified in the reply-to field?
I am using PHPMailer and the code is below:
$this->phpmailer->IsSMTP();
$this->phpmailer->Host = $server;
$this->phpmailer->Port = $port;
$this->phpmailer->SetFrom($fromEmail, $fromName); //this is email1#example.com
$this->phpmailer->AddReplyTo($replyEmail,$fromName); //this is email2#example.com
$this->phpmailer->Subject = $subject;
$this->phpmailer->AltBody = $msgTXT; // non-html text
$this->phpmailer->MsgHTML($msgHTML); // html body-text
$this->phpmailer->AddAddress($email);
Try:
$this->phpmailer->IsSMTP();
$this->phpmailer->Host = $server;
$this->phpmailer->Port = $port;
$this->phpmailer->AddReplyTo($replyEmail,$fromName); //this is email2#example.com
$this->phpmailer->SetFrom($fromEmail, $fromName); //this is email1#example.com
$this->phpmailer->Subject = $subject;
$this->phpmailer->MsgHTML($msgHTML); // html body-text
$this->phpmailer->AddAddress($email);
Try setting AddReplyTo() first before SetFrom. phpmailer needs to change this behavior. It adds the from address to the reply-to field. If you set reply-to first before the from address, it will not be able to add your from address to the reply-to header.
From a google search and first result
Adding a Reply-To Address ^
By default the Reply-To address will be the FROM address unless you specify otherwise. That is simply E-Mail client intelligence. However, you can have the E-Mail come from one E-Mail address and any replies go to a different one. Here's how:
$mailer->AddReplyTo('billing#yourdomain.com', 'Billing Department');
NOTE:
You can have multiple Reply-To addresses, just duplicate the line in the previous code example and change the E-Mail address on each line.
You will need to add this line before your from address. Please check out this for the solution to the same problem.
Following these examples, your code should look like
$this->phpmailer->IsSMTP();
$this->phpmailer->Host = $server;
$this->phpmailer->Port = $port;
$this->phpmailer->AddReplyTo($replyEmail,$fromName); //this is email2#example.com
$this->phpmailer->SetFrom($fromEmail, $fromName); //this is email1#example.com
$this->phpmailer->Subject = $subject;
$this->phpmailer->AltBody = $msgTXT; // non-html text
$this->phpmailer->MsgHTML($msgHTML); // html body-text
$this->phpmailer->AddAddress($email);

Categories