PHP mail() adding different adress for reply and reply all - php

I have a php mailing list in which, when someone sends an email to group email, it gets sent to all members of that group. So when James sends email to groupemail#tes.com, It gets sent to all members of group, i want members to be able to reply to James only by clicking "reply" in their email client or reply to group email by clicking "reply all" in their client. Please suggest how this can be done. IF i set group email in Cc header, the email gets sent to recipient twice, once from cc and once from reply-to. The code for header that I have right now is:
$headers = 'From: '. $senderName .' <'.$senderEmail.'>'."\r\n";
$headers .= 'Reply-To: '. $senderName .' <'.$senderEmail.'>'."\r\n";
$headers .= 'Cc: '.$groupTitle .' <'.$groupEmail.'>'."\r\n";
$headers .= 'X-Mailer: PHP' . phpversion() . "\r\n";
$headers .= 'MIME-Version: 1.0'."\r\n";

You can store reply all data in a array. In header portion of reply-to run a for loop to execute that data. Just formatting like single email address.

You can make your group distribution service the way it redirects messages so that one won't get the message from the group address if he is in the To-list. Unfortunately, this is how email clients work, so you can't change something anout it using the way you send mails.

Related

Website visitor message sending and receiving destination

I'm trying to figure out how to send website visitor message to administrator from "send message" form on page.
For example in verification scenario user receives confirmation message from my web mail:
$headers .= 'From: <adminemail#email.com>' . "\r\n";
to his email:
$to = 'useremail#email.com';
I'm not sure, how to send and receive visitor message:
$to = 'adminemail#email.com';
from:
$headers .= 'From: <adminemail#email.com>' . "\r\n";
via admin email to admin email and receiving visitor email for further answer just as message $mail together with $message, or I could use visitor email as sender:
$to = 'adminemail#email.com';
from:
$headers .= 'From: <visitormail#email.com>' . "\r\n";
Any guide or advise would be useful
You shouldn't set the From email to the visitors email, as this will get your server flagged from sending spam (since the email isn't really from the visitor).
Instead, you should set the From email to one on your domain (ex. form#domain.com) and set the Reply-To to the visitors email. This way, when you reply to the email it will go to the visitor correctly.
For example:
From: <form#mydomain.com>
Reply-To: <visitormail#email.com>
To: My Name <adminemail#email.com>

PHP Email Bcc from form

I've created a form to get information from end users and email to a specific person. I'd like for the form to also be emailed to the submitter. Everything works, except when I try to Bcc the submitter. If I add the line to Bcc, the email is not sent. If I delete the line to Bcc the email is sent correctly, but the submitter doesn't have a copy of the email. Here is the code,
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: $email' . "\r\n";
$headers .= 'Bcc: $email_bcc' . "\r\n";
Add the BCC Receiver to the recipients but NOT to the headers!
Using Bcc in the header should be fine. However, make sure, that your mail server is not killing the mail because of it.1
Check the return value of the mail function. This should return false, if an error occured. If that is the case, you should send an extra mail to the sender.
Windows Server seem to have a problem with this.

email sends to spam of gmail account

I have set automatically to send email to users from my website. but this email will place to spam of users with gmail accounts.However it is working fine with yahoo or hotmail accounts.
How should I solve this?
$to = "$Email";
$subject = "Greeting";
$message = 'message here';
$from = "sender#example.com";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: sender#example.com" . "\r\n" .
"Reply-To: sender#example.com" . "\r\n";
mail($to,$subject,$message,$headers);
Since your headers appear to be correct, it's probably keying on something within the message. One of the things that SpamAssassin (no idea if this is what Gmail uses) keys on is a very short message like the above containing a hyperlink or graphic, so you may benefit by actually making your message a little longer. One of the ways to find out is to send it to your own gmail account and when it appears in your spam folder, examine the headers there for any added spam information. It may contain clues as to what spam engine Gmail is using or what rules your message is breaking.
Please have a look here:
Spam sent to Contacts -
Message Delivery
Hope this helps!
it should be of smtp configuration email and site information email id should be diffrent.

Handling mail failures using PHP?

If I send an email through GMail to this address nkhkhlkhlkjlkjkljlkjlk#gmail.com
I got error like:
Delivery to the following recipient failed permanently
My question is, if I send using the PHP mail function, how can I catch bounce emails?
My code:
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
$to = "nkhkhlkhlkjlkjkljlkjlk#gmail.com";
$subject = "Testing";
$message = "Testing body";
mail($to, $subject, $message, $headers);
You can't detect such errors just by using mail(). You have to specify a valid return address and then connect to that mailbox (via IMAP or POP, there are functions for that) and check if any message bounced. Bear in mind that bounces may take a long time (even hours, due to transient errors) so you have to do this check asynchronously.
you could get the message by mail when you use this:
$bounce = 'test#domian.com';
mail($to, $subject, $message, $headers,"-f $bounce");
This will send all bounce back mails to your address
You could use PEAR MAil, it contains a parseAddressList() method which checks if the server of an email address accepts the email address. It also returns useful error messages.
The PHP mail() function does have an error status as the function return value, but it won't pick up this kind of error because it only checks that the email has been sent, not that it has been received.
(this is because it needs to return control back to the program immediately; it can't wait for a possible bounce message because they can take a long time to come back - you wouldn't want your program to sit and wait for five days just in case the email bounced, would you?)
Therefore, the only way to determine whether a message has bounced is to have a separate program which checks the mailbox which the bounces would be sent to.
You can specify the mailbox for bounces using the -f option in the mail options string (see the PHP mail() function man page for more info on this).
Then have a separate program periodically check that mailbox for bounce messages, and report them to you as required. (there are a number of PHP libraries that allow you to check a mailbox; Google will help here, or look in PEAR)
Determining which email it was will depend on the quality of the bounce message. You should definitely be able to see the intended recipient's email address, but you may not be able to tell which email it was, ie to match it up to a specific instance of when you called the mail() function in the first place.
Hope that helps.
You should login via IMAP or POP3 to your inbox and parse the email address and delivery error.
It's also worth mentioning that you can specify (while sending) custom headers to better track the message source, I believe MailChimp and others do this do track campaigns, etc...
PHP does not know anything about the mail after it got out of the mail function, so no way to do it at the same time as you send the mail.

Automated mailing list - PHP

i have an application on my site where people can sign up to receive newsletters, and then someone in a paid group can write and send one immediately to everybody who signed up...
...meaning that i need an efficient way to loop through my database of subscribers and mail them copies of the email using php.
clearly, there is the mail() function....i could put that in a loop...is there a better way?
PEAR's mail queue?
The Mail_Queue class puts mails in a
temporary container, waiting to be fed
to the MTA (Mail Transport Agent), and
sends them later (e.g. a certain
amount of mails every few minutes) by
crontab or in other way.
You could use the BCC header option and send one email with a Blind Carbon Copy list of all the subscribers.
So build the BCC string in the loop and send one email using mail()
Snippet from the PHP manual...
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
Replace 'Bcc: birthdaycheck#example.com' with $mySubscribersList
I'd suggest finding a way to loop through, and remembering who you mailed already, because if it becomes a large list of people, you script might end and you'd have to reload it.
I have done it once using AJAX, gave me a great way to track where I was in the sending proces. Counted how many people to mail, put the id's in an array, had javascript loop and make seperate calls to a php-mail-page...
-edit-
You can have a script in php, with a simple while loop, but then you should add a check in the DB to see if a mail was already sent to one person. If the script exceeds memory usage, just reload the page, and it will only sent to the ones that haven't received it yet...
Following on #paulbm's answer, why not create an alias on your server that points to all current email addresses? A short procmail script can prevent anyone other than one authorized sender using the alias.
It'd make mailing's easy, and rebuilding the list with new/changed email address would be pretty simple, too.
Try phplist (Homepage) if you need a full featured newsletter and mailinglist manager

Categories