PHP script sending with external SMTP authentication

In my work I often have clients calling with the following statement: “My PHP script which is sending with external SMTP authentication is not working. I checked all my code and it appears it is not working because of your (shared hosting) server.”

Well since it is rather not possible all the customer\”s scripts to be checked so I need something to check from the client”s side.

In such case the script provided here is very useful.

 

If you are experienced user, probably you have noticed some these lines inside the PHP SMTP sending script:

 

These are “marks” showing that the script requires installed PEAR.
What is PEAR? – In general: PEAR is a framework and distribution system for reusable PHP components. PEAR is short for “PHP Extension and Application Repository” and is pronounced just like the fruit. The purpose of PEAR is to provide a structured library of open-source code for PHP users, a system for code distribution and package maintenance, a standard style for code written in PHP, and more.

In our case you should have installed the certainly PEAR Mail package. Otherwise I am afraid that the script will not work, and you have to either use a different PHP script to send using external SMTP, or to install PEAR.

Most of the modern hosting companies have PEAR installed on their servers though.

Anyway let\”s go back to the script.
The important part is to edit the following four lines:

 

In the first one put a valid e-mail for recipient. Then set the mail server address, and the username and password for the e-mail account which this PHP script will use to send messages.

Certainly this script can be extended and a custom form added where body, subject and more information can be added.

If you are using this one only for testing purposes, copy and paste it into one external_smtp_test.php, edit the mentioned four lines and upload it using FTP.
Then go to ‘http://www.yourdomain.com/external_smtp_test.php’ and if you see this message: Message successfully sent! – and you receive the message, then you are all set.

It is not possible to describe all the errors that could happen, so if there is an error, search it in Internet to see what would be the reason.

Tags

Filed Under: PHP

Anthony Gee About the Author: Anthony G. is an IT specialist with more than 9 years of solid working experience in the Web Hosting industry. Currently works as server support administrator, involved in consultative discussions about Web Hosting and server administration. One of the first writers in the Onlinehowto.net website, now writing for Free Tutorials community - he is publishing tutorials and articles for the wide public, as well as specific technical solutions.

Comments (1)

  1. Acknatomy says:

    The script works perfect using external mail authentication. When I first landed on that page I just copied thinking it will work like that, but when I read the tutorial again it I realised it should have this Pear installed on the server first.

Leave a Reply