In this post I describe about “Send Mail using SMTP and PHP“. You can send emails with SMTP authentication using this script. Every mail needed server authentication, So you required mail server. Code is very is you can download script and implement this on your web projects.


Download “send mail using SMTP and PHP” working script here:

Download Source

Download script and go through the code for implementation.


FAQ  Send Mail using SMTP and PHP :

Question: I know to go the php.ini file but what do I add and where is it where I added it to is it

Answer: You must have an Sendmail-like SMTP server running on your computer so you can send through localhost. I would recomment to change the SMTP variable to your ISP’s SMTP server.

Question: I’ve used PHPMailer on several projects but now I’m stuck. It gives me the error:
SMTP Error: Could not connect to SMTP host.


Try setting the variable:

// if you're using SSL $mail->SMTPSecure = 'ssl'; // OR use TLS $mail->SMTPSecure = 'tls';

Question: I am getting “SMTP Error: Could not connect to SMTP host.” error while trying to send mails using GMAIL SMTP and PHPMailer. The code is working perfectly in local environment but getting error in live (bluehost) server.. Please help

Answer: According to bluehost, you cannot send emails through SMTP connections from web applications hosted on bluehost. They only allow sending through their own SMTP servers.

Outgoing Mail Server: (SSL) (server requires authentication) Supported Incoming Mail Protocols:

* POP3: port 110 * POP3S (SSL/TLS): port 995 * IMAP: port 143 * IMAPS (SSL/TLS): port 993 

Supported Outgoing Mail Protocols:

* SMTP: port 26 * SMTPS (SSL/TLS): port 465 

And it works, it sends the email out to the customers with the right email address sent from bluehost’s local SMTP servers, so when customers reply to the email address it will arrive in my google apps mail box.

Question: Does this work for gmail smtp servers?

Answer: You need to use unsecure mail servers that use port 25. Check your IP for details (if you have an email account with them, look under SMTP configuration for Outlook, Thunderbird, etc)