Authenticate Email PHP - php

I have a web app which needs to send emails to clients 'From' staff email addresses. What's the best way to prevent my messages from being flagged as spam?
For instance, if I own charles#gmail.com, I'd like to be able to send mail "From" that address with PHP in my App, without getting the "This message may not have been sent by...." message.
Right now I'm just using the mail() function within PHP, with Headers for the From, Return Path, and X-Mailer variables.
I'm generally pretty confused by everything I've read so far about SPF and DKIM, so I appreciate any advice. Thanks.

This is a very lengthy subject with lots of things to consider.
The most important rule is to not use HTML and to send only correct mails that people want, and that the recipients do not flag as spam theirselves.

For instance, if I own
charles#gmail.com, I'd like to be able
to send mail "From" that address with
PHP in my App, without getting the
"This message may not have been sent
by...." message.
If you own a gmail address you could just sent the messages via gmail's SMTP service, but keep in mind that gmail has a 500 email sent limit. Below is a topic describing how to use gmail's SMTP server with the popular PHPMailer.
Right now I'm just using the mail()
function within PHP, with Headers for
the From, Return Path, and X-Mailer
variables.
Outsourcing this is probably the way to go using for example:
http://sendgrid.com/
We also offer a Free Plan with 200
Email Credits per day.
To read pricing visit http://sendgrid.com/pricing.html
http://elasticemail.com/
No monthly committments, no minimums,
no limits. Just pay for what you use
at $0.001 / email or less.
http://aws.amazon.com/ses/
Email messages are charged at $0.10
per thousand.
http://aws.amazon.com/ses/pricing/
http://www.cloudsmtp.com/
http://postmarkapp.com/
Just to name a few which are very cheap to use without any hassle/setup.

If instead of using the mail() function, you use an SMTP mailer such as the PEAR mailer package then you can send the mail using google's own SMTP servers. This will require you to provide the correct credentials to the google account you wish to send from. This should avoid the issue you are having.

One of the first things you need to ensure is that the email "From:..." really is from your server e.g your_mailings#yourcompany.com and it must exist and be a valid email on the server where the script works. You should try setting the sendmail user at the top of your script (assumes Linux server):
ini_set('sendmail_from', 'your_email#your_server.com');
Then you add a "Reply-To:" header and use your staff addresses perhaps and recipients will at least seem to have got an email that can be replied to. Without that you probably won't even get as far as being spam, you will get blocked on the way there.
This thread shows some of that and note the comments on PHPMailer - it is a good way to handle mailing and I have found it more successful than simple mail();
PHP mail form isn't working

Related

Send emails on gmail

I am wondering if there is a way to send a quick email to my leads on gmail. I want to send each message to store them in the sent folder, I know that it can be done by create each compose message but it will give me the hard work to send the emails to each user and I don't like to use BCC because when I receive the emails from the users, I will only see one message in my inbox. I want to receive each email from each user.
Example:
http://oi57.tinypic.com/ztiy5f.jpg
I don't like to receive the email like this:
http://oi60.tinypic.com/4gl11e.jpg
Is there a way to do that through on VB6, PHP, gmail or whatever it is?
Sending mail using PHP, for example. It's not as easy as it used to be.
The sending part, is trivial. Most of the time folks use the mail command, pass parameters to it, and voila.
However, with today's overachieving spam filtering via ISPs, etc. -- Chances are very good that your email might not ever get received at its intended address. It might get there, most likely will be sent to spam, and can have several hours of delay.
The best way to send email, as far as I know, is with SMTP email in PHP. PHP mail vs SMTP

Send mail with external data through PHP

I looking into building a system that can read and send mails all by itself.
The mailserver already exists. All I want to do is fetch the e mail data with a php script running locally on the mailserver, store some of the data in an external database.
Then when an "event" is raised, I want to run a php script that get's some data out of the database, create a mail , and send it through the mail server.
I'm fairly new to this, so I hope the things I say make sense.
Here's my question: Is it secure enough to work this way?
Am I doing anything against "the rules" ?
Thanks
There is nothing wrong in doing the things this way. Its not against the rule. But Email Deliverability is not guaranteed because:
There is no guarantee that the email you send will pass the spam filters of email providers.
Number of emails you send to 1 user in a day, Any spam keyword in the mail content, user marking your email as spam etc.
Basically, there are n number of reasons why your mail server might get blacklisted by email providers.
To ensure Email Deliverability, you need to get your mail server IP whitelisted with all the email providers. (which is not easy)
I would suggest you to use bulk email sending third party solutions like Sendgrid, Madmimi, etc.
Refer: Discussion on choosing email sending service
Also, these services also gives statistics like open tracking, click tracking etc...

Php mail function not working properly to the enquiry#travel.com

in my web site i have developed a mail function see my code ..
$headers='MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html;charset=iso-8859-1' . "\r\n";
$headers .= 'From:'.$name.' <'.$email.'>' . "\r\n";
$mail_body="";
$mail_body.='<table style="border:1px solid #993300" width="400" cellspacing="3" cellspacing="5">';
$mail_body.='<tr><td style="padding-left:10px; line-height:25px;" >';
$mail_body.='<center><b>Enquiry Information</b></center><br>';
$mail_body.='Name : '.$name.'<br>';
$mail_body.='Email : '.$email.'<br>';
$mail_body.='Phone Number : '.$phno.'<br>';
$mail_body.='Package : '.$package.'<br>';
$mail_body.='Category : '.$category.'<br><br>';
$mail_body.='Vehicle Type : '.$vehicle.'<br><br>';
$mail_body.='Traveling From : '.$travelfrom.'<br><br>';
$mail_body.='Arrival City : '.$arival.'<br><br>';
$mail_body.='Date : '.$date.'<br><br>';
$mail_body.='Adult : '.$adult.'<br><br>';
$mail_body.='Children : '.$children.'<br><br>';
$mail_body.='Food : '.$food.'<br><br>';
$mail_body.='Travel Requirements : '.$requirement.'<br><br>';
$mail_body.='Duration : '.$duration.'<br><br>';
$mail_body.=' promotions : '.$promotion.'<br><br>';
$mail_body.='Addons : '.$addone.'<br><br>';
$mail_body.='Preferred Destinations : '.$destination.'<br><br>';
$mail_body.='</td></tr>';
$mail_body.='</table>';
$mailSend=mail('enquiry#travel.com', "Country Travelmart" , $mail_body, $headers);
if($mailSend){
header("location:success.html");
}else{
header("location:sorry.html");
}
I see success.html page, after the mail function. But the mail is not present in 'enquiry#travel.com. I have changed the mail address to my email address, i got the mail. Then why mail is not sent in 'enquiry#travel.com.
Does any one know this?
Please reply
I think using PHPMailer can help you to increase the chanse of preventing emails as spam.
Junk mail? Email being filtered? Does that server that is sending the Email resolve the travel.com to the same IP as you do?
It is apparent that your PHP code does not have an error in it if it is sending to other Email addresses.
Some mail servers require certain settings to allow you to email, such as a secure SMTP connection to the server which php cannot handle within its native libraries.
Pear has a library you can use to attach SMTP authentication at: http://pear.php.net/package/Mail
Additionally, you might wish to troubleshoot by setting your own email address as the sender - in the event of a bounce-back email, you will then be able to receive it and troubleshoot further.
If the mail is getting through on other accounts and returning success for this account but never showing up, then the problem isn't with the code, it's with your message getting blocked by the destination server.
Possible reasons:
The destination server thinks it's SPAM. This is almost certainly the case. I worked for a cloud spam service, and web developers using PHP mail and other blind transfer agents hated us.
The destination server only allows certain IPs to send (usually a firewall or whitelist). You probably can't fix this unless you know the IT guy for travel.com and buy them a beer.
The destination server rejects messages with specific headers it doesn't understand, aren't set at all, or generally off.
Possible solutions:
The only possible solution that would involve keeping your current code in place would be changing or adding a header to the outgoing message. This is probably not the best fix because:
The headers could be fine and the message is getting blocked for other reasons.
If it is a header, tracking down which one will require getting the message back with the full headers (usually a bounce reply will have them, but not always)
Using PHP's mail function is outdated and not ideal for any kind of mail campaigns (for the reasons your seeing)
Using a 3rd party mail library like Pear's Mail class or PHPMailer (which I use). Be aware, however, that the reason these work more reliably is because you provide the SMTP server details and credentials, the same as you would for Outlook or Thunderbird. PHP's mail function uses the host server's SMTP server to send out, which causes issues like yours, but also doesn't require a password and permission to use. Having said that, it is better to send via a registered and verified address, both because it's less spammy and because your account's SMTP server can vouch for you, so to speak. But I would invest in getting an email account just for using in your PHP scripts, rather than using your personal account. Also, be aware that GMail is a real headache for this purpose, so just skip it if you can.
Dedicated mass mailing accounts, like Amazon SES or MailChimp. The best of both worlds, because they do bulk mailing better than your SMTP server ever will, it's tied to a user account you set up with them, not your actual email address, and most of them provide PHP libraries. The catch: they don't come cheap. The economics of scale to get a good Return on Investment is tons of emails daily.
My recommendation is to go with a free and respected mailer library and pay (if you aren't already) for a new email address just for the site to send mail. When it gets to the point where you're sending more emails than your mail server can handle in a day, look at a mass mailer service.

How to make email sent using php's mail() reflect in "sent items" of sender's mailbox

Let's assume my php script sends a mail to receiver#example.com using the function mail(). In the $headers parameter of mail(), I specified sender#example.net. If receiver#example.com replies to this email, he may or may not include the whole conversation while replying. This will make impossible to know, for what the receiver is replying.
If there is a way which sends the mail sent by mail() directly to the "sent items" box of the sender#example.net, It would greatly help.
I know an alternative way. That is to send sender#example.net a copy of mail sent to receiver#example.com whenever a mail is sent using mail() but that would reach the inbox which would again make it clumsy to track the conversation.
Please tell me if there is a way to reflect the sent mail in the "sent items" box of sender#example.net.
Thank you
Peace to all...!
It's not to simple...
PHP mail() just send an email throug system "sendmail" command, simplified it's just an smtp client.
What you need is an IMAP client - PHP has a good IMAPlib extension, let's go to try it. Btw, you need your user account to put the email to "sent items", may be it's not solvable.
Edited:
You should follow the instructions and examples on these sites:
http://hu.php.net/manual/en/function.imap-mail-move.php
http://hu.php.net/manual/en/function.imap-mail-copy.php
There are several example, I think you can do what you want with help of those.
You have to send a message via SMTP. PHP's mail() function doesn't provide this functionality, but you can write your own or use some existing solution. For example, Zend_Mail from Zend framework, or PEAR's Net_SMTP package
Main idea is that you connect to SMTP of sender#example com and sends a message. And you'll get what you need.

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.

Categories