● How to test your sites Email system

Mon Jan 02, 2023 1:35 pm
Clan Leader
Top Dog
Nuke Dev / Coder
3036 Posts
coRpSE
Online
Most Played:
This week: 14.5hrs.
Total Played: 2,701hrs.


  
Must be married.
Reputation: 7373
votes: 7
First off, if you are using an SMTP server for email, this is not for you. This is for testing PHP mail.

Today, I had another friend send me a PM telling me that his site move was successful to the new host, but wasn't sure if his site was sending emails. Well, that PM he sent got me remembering that I wrote a script a while ago when I moved my site and set up my email system, and need to know if the new address was working along with my site sending out PHP emails. So to test this, it's a very simple file that you just open it, edit the first two variables, then upload it to your site then go to that file path. If it says a message has been sent, you know you are all good.

Below is the code, and attached for you that don't want to create the file, I did pack it up into a zip.

Here is the code:

Code: [ Select all ]

<?PHP
    //Place the email address that your site is going ot be using
    $sender = 'admin@YourSite.com';
    //Place any email address that you can visit that is different from the sender email.
    $recipient = 'YourPersonalEmial@yahoo.com';

    //----------------------------------------------------------------------------------
    // Do not edit below unless you know what you are doing.
    //----------------------------------------------------------------------------------
    $subject = "PHP Mail Test";
    $message = "If you are seeing this message in your email, then your site is sending emails.";
    $headers = 'From:' . $sender;

if (mail($recipient, $subject, $message, $headers)) {
    echo '<strong>Email Sent</strong>';
} else {
    echo '<strong>Error: Email not sent</strong>';
}


You will see two variables that need to be edited,
  1. $sender - Place the email address that you are going to be using for your site.

  2. $recipient - Best to use your private email for this.


Once you change both those, upload the file to the root of your site, (if you're creating the PHP file, give it any name, then upload it).
Once uploaded, go to YourSite.com/email-test.php and see if it works. When you're done, remove the file from your site, please DO NOT leave it.

Just know, this is just for those of you that need to verify its working. If you already know that it's working, this is not necessary. I am just putting it out there for others to use.


Expand
Forums ©