PHP Mail Sending via SMTP only to BCC receivers - php

I am writing a mailing List in php and need a way to force while sending a mail via smtp (Postfix) on localhost just really sending that mail to the BCC receivers.
(Having To and Cc headers sending them in the mail, but not sending the mail TO them)
The reason: If a mail is sent to the list it was sent to those receivers before; In the php script, I edit the mail (Removing forbidden Words, adding a footer with signout-link etc.) and want to send it than via smtp (mail() isnt good, it does no error handling)
Is there any Class or simple way to do that? or is it possible to stay in the postfix queue (The Mail is piped to the php-script)
The Mail, I send has as to: the mailing.list-adress (Because it has to be shown that the mail was delivered to the mailing list) and all other Tos, but the script should not send them to that adresses, it just should send to the bcc adresses.
The Mail-Flow is
Sender => specific-list#server.de => lists#server.de => php-programm => drop
Every 5 Minutes (Or other time the user specified) the List will be rolled out:
mail in database => script => receipients as bcc, to is list-adress (specific-list#server.de)
The Mail looks like:
From: original-sender#original-server.org
To: specific-list#server.de, <any other tos from original mail>
Cc: <any ccs from original mail>
Bcc: <all the list subscribers> //JUST REALLY SEND TO THIS ADRESSES
Subject: [Listname | Topicid] Topic Name
Content:
<original content>
--
signature for unsubscribe, etc.
I have an Idea how I could solve this, but need help for doing it.
I create a internal mail-address, that forwards to my real receipients
I send the mail to that address
Postfix has to handle that mail not as an outgoing mail but as a new mail delivered to that adress.
Because it is a received mail, postfix doesnt deliver to all other Receivers, it just delivers to that specifix address (that is a Forwarding)

Whenever you send mail, by the rules established universally, you need to have a To recipient. If you want to send the mail to yourself or to an address just for the purpose, fine. Once you have a To you can go ahead and create your bccs.

Related

PHPMailer: Set custom header to identify it inside the bounce email

I'm sending emails with PHPMailer. When an email is bounced it goes to an account like this: account_bounces#domain.com
Inside my email client where I manage this account (account_bounces#domain.com), I have the option to adds filters in order to redirect an email to any other email account, based on the comparation of fields like "Subject", "From", "To" and so on. That's good.
The problem is that the bounced email loses all of my headers/Subject...that I set with PHPMailer because it's ALWAYS composed by the server as it follows:
Subject: Undelivered Mail Returned to Sender
From: MAILER-DAEMON#llsd409-a04.servidoresdns.net
To: account_bounces#domain.com
Date: Today hh:mm
So I have no guide marks to use for adding a filter.
So, is there any way to set a mark(like a custom header, etc...) in PHPMailer that REMAINS in the bounced email?. For example, something like having this:
Subject: Undelivered Mail Returned to Sender (bounce_redirect)
So the word "bounce_redirect" in the Subject(or wherever) would indicate my email client that this email has to be redirected.
Thanks in advance.
Unfortunately there is no way you can force this issue in headers; The only way around it is to use VERP addressing, which is the only way that you can guarantee that it preserves info about the message and what address it was originally sent to. It's common for MS Exchange to send bounce messages that do not mention the original address the message was sent to at all, so VERP is the only solution.
For your example, a typical VERP address would be:
account_bounces-user=domain.com#domain.com
You mail server would be set to spot the account_bounces prefix and remove it, and convert the = to a # in the local part to extract the original address.
In PHPMailer you would set this as your Sender property, like:
$mail->Sender = 'account_bounces-user=domain.com#domain.com';
This will be used as the SMTP envelope sender, and converted to a Return-Path
header by the receiving server, and thus will be used as the RCPT TO address (the bounce destination) when the message gets bounced.
You can take this further and embed additional info in the Sender address that can be used to identify the mailing list, a specific mailshot etc.

Swift Mailer dont't send to "to" but to bcc

I am working on a Mailing-List system combined with an online Forum.
Mail Input (Via Postfix forward to Script) works and after receiving an E-Mail the script should process it and send it out.
Processing and everything works, sending too.
I Have a list (list#example.com) that is accessible for few adresses (eg user1# user2# user3#example.com and user1# user2# user3#otherdomain.com)
If one user sends a mail to the list it is delivered t oa php script, that does the processing (Checking if user has rights, adding some Information to the Message eg. sign out link) and sends the mail out to the list-recipients.
But I want to have a behaviour like this for the from the script Outgoing mail:
From is original Sender
To in the mail is the Mailing list (list#example.com)[X]
Reply To is the mailing list
Subject is Modified
Body is modified
Real To is the receiver of the list.
Here's the problem:
[X] So I want to send out a Mail, that just delivers to bcc and not to to, but has a to address.
I am Using swift-mailer in Codeigniter.
If I'll send it to the list itself, I would create a infinite loop, because all mails to the list
The To field indicates a recipient. To not have a To recipient, leave the To field empty.
In order to workaround this and include a To field that will not be a recipient, I believe some lists use a X-BeenThere header:
X-BeenThere: listaddress#domain.org
To: listaddress#domain.org
Then when the list receives the email back — which it will do along with all your BCC "real" recipients — it can simply ignore it because X-BeenThere matches its address. This prevents the loop.
I do not know how standard this is, whether Swift-Mailer supports it and if not how to make it so. I observed this precedent with the gpsd-users list.

PHP email form, how to bypass host limitation? (Can ONLY send/receive IF hosting sender/receiver)

My webhost ONLY allows sending/recieving emails IF either the sender or reciever is hosted with them. (freehostia.com)
This is a huge disadvantage to me (and I'm assuming everyone else), because of the way my website works.
(My website: I have a classifieds website where CustomerA posts an ad with her email and CustomerB replies via the email form with his email. Neither email is hosted with my host.)
I asked if I could use an external SMTP server (such as Gmail) to bypass the limitations, and they said "Even if you set an external MX record for your domain you will not be able to send e-mails via your mail forum, if you do not use a mailbox from your hosting account with us as a sender or recipient."
Theoretical Workaround:
Auto-enter and hide my hosted email into the "email" section of the form
Have a new section for customer to input their email
When a message is sent, embed customers message and email into a default message. It will look like this:
To: customerA#example.com
From: DONOTREPLY#example.com
Subject: You have recieved a message!
Body: Blahblahblah (customers message) blahblah. To reply, email: customerB#example.com
Sorry about all the confusion. Would this work? Should I give up? I really like my host, but should I switch? Or is there a better workaround?
While you don't need to send through a different server, you can just send to whom you need and set the reply to any address you want.
The mail function allows you to set your own headers as a final parameter.
$headers = 'Reply-To: someone#some_other_domain.com\n\r';
mail($to, $subject, $body, $headers);
You can set the reply-to address.
That way even though the email is sent from your address, when the recipient hits reply it creates an email to the address given in the reply-to.
I'm not sure what you are using to send mail but there are some examples in the PHP documentation mail function - http://php.net/manual/en/function.mail.php

How to hide sender email address using phpmailer?

I am using phpmailer to send email. I need to know how to hide or mask sender email address
You can specify any sender email address anyway, since SMTP by itself does not place any requirements on sender email addresses.
If the actual SMTP server you use places restrictions on email addresses (e.g. corporate servers which do not allow sender emails outside of the company domain) there's no way around that, unless of course you can influence the mail server configuration.
Update:
You say in a comment that you want to use gmail to send email where the sender's address is not a gmail address. There is no way to do that.
This is a rare situation you have here... if you do not have a mail server you can still tell PHPMailer to send from a different address just set the From attribute of the PHPMailer object to the address you want. But Wait! if your server doesn't exists, the client can't verify the account and then your mail will more likely be deleted (moved to spam in the more benevolent scenario). If you are trying to mimic third party mail, I'll help you no futher.
Note: Your mail server may be valid but clients are still unable to verify it, and thus you are getting mails delivered to spam or deleted. Check "Must Read" to below to have some inside on how to solve this.
On the other hand, if you already have a mail server, then tell PHPMailer you want to use it, set the Host and Port attributes to your domain name and port respectively. The same if you want to use an account form a different server, remember to set the attributes Username and Password correctly, you may also need to set SMTPAuth = true; and SMTPSecure = 'ssl'; depending on the server. [Note: Username and From may differ]
Now, if you want to use an account from Gmail, you could easily set an alias in Gmail to send as another account [Go to Settings-> Accounts And Import -> Send mail as -> (click) Send Mail From Another Address], that can be the case if you have a mail server but you cannot afford to have it online, you will need to start your server so you can receive the confirmation code Gmail generates to verify your account. Check recommended read for PHP side configuration details.
Lastly if for some rare circunstancies you can't tell PHPMailer to use your mail server, but you do in fact have one, and that one is able to recieve the mail... you can use AddReplyTo('me#example.com', 'My Name'); Most clients will understand that any reply to the message must be (unless explicitly defined by the user) directed to "me#example.com" in this case.
Disclaimer: I take no responsibility of any harm result of the use of the method I mention here, such as (but not limited to) your mail account getting banned.
Must read:
Coding Horror on sending mail via code
Recommended read: PHPMailer Tutorial (old version)
No need (neither a good way) to hide or mask whatsoever.
I assume you already know how to use the class you are talking about.
You probably have some variable for sending email, like
var $From = "someguy#whatever.com";
you can type whatever you want into that email address. Gmail dont care what email things is sent from.
And no, this dosent sound very legit.
One more thing: Gmail requires a gmail account to relay mails. Its no problem, it wont be visible.
You want to "show the company email address as sender" but you "didn't (sic) have any email server"?
Can anyone actually send you email at your company email address? If so, use that server which is hosting your email to send out from.
If you don't really have a company email address, then I suggest you get a gmail address like companyname#gmail.com and just send from that. Otherwise the email will appear as spam to a great many of your recipients.
Now, if the people you are about to send an email to actually signed up to be on your mailing list then you can use a third party application like Constant Contact to do your broadcasts from.
If they haven't, then I suggest you not send an email at all.
in mail headers you can have both a Sender: and a From: header which in most mail clients is displayed as either just the From or in some cases Sender on behalf of From, using this way is a nice and clean way to be able to send From a different mail address then the actual Sender mail server
This is highly illegal.
var $From = "someguy#whatever.com";
Is the only option your have for trying to hide email address. But no matter what your email will be inscribed with IP. Someone who knows what they are doing will still be able to trace the email back to the source.

Sending BCC emails using a SMTP server?

I've had this noted down on some of my code for a while:
/**
* Add a BCC.
*
* Note that according to the conventions of the SMTP protocol all
* addresses, including BCC addresses, are included in every email as it
* is sent over the Internet. The BCC addresses are stripped off blind
* copy email only at the destination email server.
*
* #param string $email
* #param string $name
* #return object Email
*/
I don't remember where I got it from (possible source) but that shouldn't be relevant to this question. Basically, whenever I try to send an email with BCCs via SMTP the BCC addresses are not hidden - I've read the whole RFC for the SMTP protocol (a couple years ago) and I don't think I'm missing anything.
The strange thing is, if I send an email with BCCs using the built-in mail() function everything works just right and I've no idea why - I would like to roll my own email sender but I fail to understand this.
Can someone please shed some light into this dark subject?
The BCC addresses are not stripped off at the destination email server. That's not how it works.
How SMTP actually works
The sender will send a list of RCPT TO commands to the SMTP server, one for each receiver email addresses, and this command does not distinguish whether the receiver is a normal To, CC or BCC type receiver.
Soon enough after calling the command that tells the SMTP server who's the sender, who's the server, and everything else, only then the sender will call the DATA command, in which will contain the content of the email - which consist of the email headers and body - the one that are received by email clients. Among these email headers are the usual from address, to address, CC address.
The BCC address is not shown to the receiver, simply because it's not printed out under the DATA command, not because the destination SMTP server stripped them away. The destination SMTP server will just refer to the RCPT TO for the list of email addresses that should receive the email content. It does not really care whether the receiver is in the To, CC or BCC list.
Update (to clarify): BCC email addresses must be listed in the RCPT TO command list, but the BCC header should not be printed under the DATA command.
Quoting a part of the RFC that I think is relevant to your case:
Please note that the mail data includes the memo header items such as Date, Subject, To, Cc, From [2].
Rolling out your own email sender
A couple of years ago, I frankly think, is quite a long time back to assume that you still memorize end-to-end of RFC 821. :)
Very late, but the accepted answer is essentially wrong.
First off, SMTP has nothing to do with BCC. SMTP, as a protocol, is concerned only with a return path (the MAIL request), a list of recipients (the RCPT request), and the data to be transferred (the DATA request). If you want to send an email to somebody via SMTP, then you have to supply their address in a RCPT request, period.
The contents of an email - the DATA, effectively - are specified completely separately, in RFC2822. There's a lot of latitude in how BCC should be handled. The spec gives 3 ways of handling BCC, and in only one of them is the BCC stripped out while preparing the email. If I use Thunderbird as an email client, for example, and point it to an SMTP server, and then look at the message on the line, then I find that the Thunderbird BCC has gone (from the SMTP DATA), and the SMTP connection instead contains a standard RCPT request for the bcc'ed address. So, Thunderbird converts BCC to RCPT, but that's not the only way to do it.
Another place to handle BCC is at the MTA - in other words, whatever SMTP server your mail client is pointed to. Sendmail, for example, searches all of the To, Cc, and Bcc lines in the SMTP DATA, and then constructs an address list from those lines, and then removes the Bcc line. You can persuade Sendmail to keep the Bcc if you want to. If sendmail isn't the destination MTA, then it will connect to another MTA over SMTP, and send the recipient addresses via RCPT. In other words, if sendmail is the destination MTA, and it gets a Bcc, it will strip it out, contrary to Amry's statement.
There's also some confusion in the comments. You can specify RCPT addresses to any domain, not just a list of addresses in the same domain. The MTA has to look up the MX records for the destination domains to work out where to send everything. The google.com and yahoo.com statements are wrong.

Categories