Social Networks

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)

None found.
  1. i set every thing but it gives an error

    Notice: Undefined variable: HTTP_HOST in C:\xampp\htdocs\SMTPpmail\SMTPClass.php on line 38

    Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\SMTPpmail\SMTPClass.php on line 39

  2. PHP Training In Mumbai says:

    You can even easily use SMTP in PHP code by using PHPMailer. It has proper settings and functions that will help you to send email via SMTP.

Leave a Reply

Your email address will not be published. Required fields are marked *

Allowed Tags:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>