First of all, your server needs to be well configured or be considered as spammer until you are. This is because of Sender Policy Framework (SPF). This should be done at server level.
There are several locations that explain how to email from various languages, so I’ll focus on solving your main problem, not how to do it in the language.
Direct upload solution from your servers
Configure your server to work to meet the requirements of the Sender Policy Framework. This is not trivial, and you will be responsible for seeing complaints of SPAM, or even with it you may have IP banned.
This solution tends to give more trouble if the amount of sending emails is huge and at the same time.
Shipping solution via gateways Paid email guaranteeing delivery
If you can’t set up SPF, a viable option is to hire email gateway services such as Amazon Simple Email Service (Amazon SES), that release access data (for example, SMTP data that you could send from anywhere) and will do the service for you.
This solution tends to be simpler than setting up SPF, but is more expensive. It allows sending large amount of emails with less headache.
Simple and functional solution for few emails
Create a Gmail account, enable SMTP, and configure your framework to upload as if it were through that Gmail account. It works great and is the cheapest and easiest to ensure that your emails will reach 100% of the time, but requires you not to send MANY emails at the same time.
If you use the Google Apps for Business the email will be exactly that of the client’s domain, but the free quote nowadays does not allow many different accounts, but it is enough for small businesses.
Tip: use a service like Sendgrid or the Mailchimp.
– J. Bruni