If you're running the script from a developer server at home, you're most likely having problems with your ISP having blocked port 25.
What I would recommend you to do is use a Transactional Email service such as:
Why?
- Has HTTP API support (runs on port 80/443, so no ISP blocking). I.e. easy to run from home.
- Future-proof. You don't have to think about hosting your own SMTP-infrastructure. Scaling it once your sendings increase.
- You don't have to think about delivery. Being blocked because the IP you are sending from isn't whitelisted, the list goes on.
- Statistics. Let's you track Total Sent/Clicks/Opens/Bounces.
How?
Since I am one of the developers behind AlphaMail, I of course recommend you to use it (but not only because I'm one of the developers behind it, but because it's great! :)). And since you're using PHP, it's easy to get going with the AlphaMail PHP-client:
include_once("comfirm.alphamail.client/emailservice.class.php");
$email_service = AlphaMailEmailService::create()
->setServiceUrl("http://api.amail.io/v1")
->setApiToken("YOUR-ACCOUNT-API-TOKEN-HERE");
$person = new stdClass();
$person->userId = "1234";
$person->firstName = "John";
$person->lastName = "Doe";
$person->dateOfBirth = 1975;
$response = $email_service->queue(EmailMessagePayload::create()
->setProjectId(12345) // Your AlphaMail project (determines template, options, etc)
->setSender(new EmailContact("Sender Company Name", "from@example.com"))
->setReceiver(new EmailContact("Joe Doe", "to@example.org"))
->setBodyObject($person) // Any serializable object
);
Another great thing with AlphaMail is that it separates logic from design. So you never have to bloat your code with ugly non-standard (email) HTML again. And once you need to change things it's no digging in code, just log into the AlphaMail Dashboard and edit your template immediately. Also, the templates are built using the simple template language Comlang, so they are highly personalizable.
<html>
<body>
<b>Name:</b> <# payload.firstName " " payload.lastName #><br>
<b>Date of Birth:</b> <# payload.dateOfBirth #><br>
<# if (payload.userId != null) { #>
<a href="/sign-up">Sign Up Free!</a>
<# } else { #>
<a href="/login?id=<# payload.userId #>">Sign In</a>
<# } #>
</body>
</html>