Configure SMTP for Sending Emails

| January 9, 2014

Do you want to send emails with just one mouse click? You can make this process fast and convenient by configuring SMTP in your Jelastic server.

SMTP stands for Simple Mail Transfer Protocol. It is a standard for transmitting emails over the Internet. SMTP is used when email is delivered from an email client to an email server or from one email server to another. Communication between sender and receiver is performed via command strings and delivering data using a reliable data stream channel, and  usually a TCP connection. The greatest asset of SMTP is its simplicity and reliability.

It's rather easy to configure your server for using the SMTP communication rules. And, in this article, we will show you how to do this using Jelastic PHP hosting. Here we present two variants of mailing with SMTP - using PHPMailer or a custom form for email sending.

So let’s get started with your PHP environment creation in the Jelastic Cloud.

Create an Environment

1. Go to and sign up for a new account if you haven’t done so yet, or login with your Jelastic credentials by clicking the Sign In link on the page.

2. Select the Create environment button and navigate to the PHP tab in the opened dialog box.

3. Choose the Apache application server and specify cloudlet limits for it.

Then, enable Public IP feature for the Apache node.

Type the name for your new environment (for example, phpmailer) and click Create.

create php environment

Now you can proceed to the SMTP configurations. Firstly, we’ll describe the settings of PHPMailer.

PHPMailer for Sending Email

PHPMailer is a classic full-featured email sending class for PHP, compatible with PHP v. 5.0 and higher. Let’s examine how to use it in the Jelastic Cloud.

1. Download the PHPMailer script (here we provide you with our custom version which excludes all extra settings and is targeted only on SMTP).

2. Navigate to the Deployment Manager and Upload the downloaded package to the Jelastic dashboard.

upload button
upload phpmailer archive

3. When the upload is completed, deploy PHPMailer package to the environment you have created earlier.

deploy php mailer

4. Next, click the Config button next to your application server and open webroot >{context_name} > config.php file.

phpmailer configuration

5. Here you need to specify all of the necessary data to configure mailing:

  • via localhost
  • via some specific email account

Let’s take a closer look at these settings:

Sending via Localhost

You can send emails directly from your app without specifying a real email account. In this case, you don’t have any restrictions on frequency and quantity of sent emails, but your mailings can be detected as spam.

For using this configuration you should state the following parameter values:

  • host:  state localhost value
  • auth: state false (it disables the authentication as it isn’t required for localhost)
  • username: state the name you would like to be shown as a sender name
  • addreply: state the email which will be used for sending replies to your mailings. Note that it is an obligatory parameter to state the value.
  • replyto: state the same email as for addreply parameter
email via localhost

Save the changes made. After that you can click the Open in browser button next to your environment and you’ll see the form for sending email.

test phpmailer info

Enter the test info in the fields and click Submit. In a few minutes this email will appear in your inbox.

test localhost email received

Note: if you didn’t receive the email within a few minutes, check your Spam mail folder.

Sending via a Real Email Account

In case you have a special email account registered for your mailings, you can also use this. In such a way, your emails most likely won’t drop in the spam folder, but you’ll see some restrictions regarding, for example, amount of emails you can send (this depends on your email provider’s rules). In the following example we will use a email account.

You can use the following configuration as an example:

  • host:  state ssl://
  • port: 465 (SMTP port of your email provider, gmail in our case)
  • username: state the email account you would like to use
  • password: state the password to the account you’ve specified in the username line
  • addreply and replyto: state the same email as in the username line (the one you are going to use for mailings)
gmail email via smtp

Save the changes made. Click the Open in browser button next to your environment to see the form for sending email.

test phpmailer info

Enter the test info in the fields and click Submit. In a moment this email will appear in your inbox.

gmail smtp email received

That’s all that is required for the PHPMailer settings for SMTP email sending. Using this method, you can try to configure any other email system.

Now, let’s consider how to set your own custom form for email sending via SMTP.

Using a Custom Form for Sending Email

You can prepare your own custom code for the form and set it to be used for sending emails. Follow our instruction to configure this properly in Jelastic using our sample of the form:

1. Select the Config button next to the Apache server.

config apache mail

2. Navigate to the webroot/ROOT (or another context) folder and create a new file there, for example, mailtest.php.

mailtest page

3. Paste the code of your custom form to the file created and Save the changes made.

You can use our example:

<form method=POST ation=#>
From <input type=text name=from><br />
To <input type=text name=to><br />
Subject <input type=text name=subj><br />
Type your message  <input type=text name=text><br />
<input type=submit name=sub value=Send>
if ($_POST['sub']){
 system ("echo {$_POST['text']} | mail -s {$_POST['subj']} -r {$_POST['from']}  {$_POST['to']}");}
mailtest php code

4. Then select Open in browser, your environment and add the name of your file to the end of the URL. You will see the following type of form:

email sending form

5. Fill in the required fields and click Send.

Note that you can use both localhost and a real email account for sending emails (just type "localhost" or the necessary email into the From field).

mailtest form filled

As a result, the recipient will receive the email. Note that the email can also be assigned to the spam folder.

custom form email

It's that easy! Now, you can perform your mailings directly from your application, hosted with the Jelastic platform. Enjoy and feel free to leave your feedback in the comments below.