Email via External SMTP
External SMTP for Email Sending
PHPMailer for Email Sending
PHPMailer is a PHP email-sending library that can be configured to deliver messages through localhost or an external SMTP account.
Create the PHP Environment
1Create the environment
Sign in to the dashboard, click Create environment, open the PHP tab, and select an Apache application server.
2Configure resources and networking
Set the Cloudlet limits, enable a Public IP for the Apache node, enter an environment name such as phpmailer, and click Create.
Upload and Deploy PHPMailer
3Download the PHPMailer package
Download the PHPMailer package prepared for SMTP use.
4Upload the package
Open Deployment Manager and upload the downloaded archive.
5Deploy the package
After the upload finishes, deploy the package to the previously created environment.
6Open the configuration file
Click Config for the Apache node and open webroot/{context_name}/config.php.
Send Through Localhost
Messages can be sent without authenticating through a separate email account. This configuration is simple, but such mail may be more likely to be classified as spam.
| Parameter | Value |
|---|---|
host | localhost |
auth | false |
username | Sender name displayed to recipients. |
addreply | Reply address. This value is required. |
replyto | Use the same address as addreply. |
Save the file, click Open in Browser, enter a recipient, subject, and message, then submit the form.
Send Through an Email Account
An external SMTP account can improve sender identity and deliverability, although the provider may impose sending limits. The source example uses Gmail SMTP.
| Parameter | Example Value |
|---|---|
host | ssl://smtp.gmail.com |
port | 465 |
username | Email account used for sending. |
password | Password or provider-issued application credential. |
addreply | Use the sender account address. |
replyto | Use the sender account address. |
Save the changes, open the application in a browser, submit the test form, and verify the received message.
Use a Custom Email Form
1Open Apache configuration files
Click Config beside the Apache server.
2Create the form file
Navigate to webroot/ROOT, or another deployment context, and create a file such as mailtest.php.
The source page provides this basic form and mail-command example:
<form method="POST" action="#">
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">
</form>
<?php
if ($_POST['sub']) {
system(
"echo {$_POST['text']} | mail -s {$_POST['subj']} -r {$_POST['from']} {$_POST['to']}"
);
}
?>
Open the environment in a browser and append the new filename to the URL, for example /mailtest.php.
Submit the form and verify that the recipient receives the message.
Security and Delivery Notes
- Use the SMTP hostname, port, encryption mode, and authentication requirements supplied by the email provider.
- Use an application-specific password or supported token when the provider does not allow the regular account password.
- Keep SMTP passwords outside publicly accessible files and source repositories.
- Restrict access to test forms and remove them after verification.
- Check the Spam folder when a test message does not appear in the inbox.
- For production mail, configure valid sender-domain records and follow the provider’s sending limits and policies.
