How to send test messages via SMTP
Sometimes you may need to send a test message through SMTP to confirm that your configuration works correctly or to replicate a specific issue. While simple tools like SMTPer can help you test basic sending, creating your own test setup gives you much more control over the message â including headers, attachments, content, and authentication details.
This guide walks you through setting up a local test environment and sending a message through Postmark using PHPMailer.
1. Install the necessary tools
Youâll need three main tools:
-
Homebrew â a package manager for macOS.
-
PHP â for running your test script.
-
A code editor â such as Brackets, Visual Studio Code, or Sublime Text.
Install Homebrew
Visit https://brew.sh/ and copy the installation command from the site.
Then:
-
Open Terminal on your Mac (press Command + Space, type âTerminal,â and hit Enter).
-
Paste the command and press Enter.
-
Enter your Mac password when prompted.
-
Wait until you see
Installation successful!.
Install PHP
Once Homebrew is installed, run this command in Terminal:
This installs the latest version of PHP. You can confirm itâs installed by running:
You should see something like PHP 8.1.x.
2. Download and set up PHPMailer
PHPMailer is a popular library for sending email through PHP and makes it easy to work with SMTP.
-
Download PHPMailer from GitHub (click the green Code button â Download ZIP).
-
Extract the ZIP file to your Desktop or another folder.
-
Open the folder in your code editor.
-
Locate the example file â typically named
php_mailer_example.php.
This file contains properties like Username, Password, Subject, SetFrom, etc. Each line is commented for guidance. Youâll just need to edit the values inside the quotes.
3. Update the email details
Hereâs what to update in the file:
Authentication
Add your Postmark Server API token for both the username and password fields:
Message stream (optional)
By default, messages will send through your Transactional message stream.
If you want to send through a Broadcast or another stream, add or edit this header:
Replace broadcast with your actual message stream ID.
Sender and recipient
Use verified sender addresses from your Postmark account:
If youâre not including CC or BCC, remove those lines entirely â leaving them blank will cause an error.
Email body and subject
Attachments (optional)
You can safely leave this line in your file (even if you donât include an attachment):
If you do want to include an attachment, make sure the file exists in the same folder as your PHP script.
â Save your file when done.
4. Send a test message
Now youâre ready to send your test message!
-
Open Terminal again.
-
Navigate to your PHPMailer folder (for example, if itâs on your Desktop):
-
Run your test script:
If everything is configured correctly, youâll see output similar to this:
Â
That unique âqueued asâ ID is the Postmark Message ID â you can share it with Postmark Support if youâd like us to confirm delivery in our logs.
5. How to include an attachment
To attach a file, add this line anywhere before sending:
-
The first parameter is the file path.
-
The second (optional) parameter is the filename as it will appear to the recipient.
For example, if your file is located in the same folder as your script:
6. Troubleshooting
| Issue | Possible Cause | Fix |
|---|---|---|
Could not authenticate |
Incorrect Postmark token or wrong SMTP credentials | Verify youâre using your Server API Token for both username and password |
| No message appears in Postmark | Not sending from a verified sender or wrong stream header | Check your From address and ensure the correct stream |
| âEmpty addressâ or syntax error | Missing or blank field | Remove unused fields like CC/BCC |
| âConnection refusedâ | SMTP blocked by firewall | Try from a different network or confirm port 587 is open |
Summary
Youâve now created a full test setup for sending emails via SMTP.
This approach gives you full control over message details â including headers, attachments, and streams â making it a powerful way to troubleshoot delivery or replication issues.
If you run into any problems or want help reviewing your test results, you can contact Postmark Support and share your message ID or test output.