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.