New to PHP, so please bare with me.
I created a function to send an activation email. To test it, I setup a test page that would run the function. The page is telling me that the mail was sent (i.e. it prints “Mail Sent.”) … but I never receive any email.
I’ve tried several different “to emails” (just in case the mail server for one was being picky). I also checked my SPAM folders for each account, but the emails aren’t showing. Can anyone see any issue with the code below?
<?
include_once('configinfo.php');
?>
<html>
<head>
<meta charset="utf-8">
<title>Email Test</title>
</head>
<body>
<?php
// site_email and activation_link are defined in configinfo.php.
// activation-email-template.html is a file in the same location as this test page
function send_activation_email($email, $code) {
// Email Subject
$subject = 'Account Activation Required Test';
// Email Headers
$headers = 'From: ' . site_email . 'rn' . 'Reply-To: ' . site_email . 'rn' . 'Return-Path: ' . site_email . 'rn' . 'X-Mailer: PHP/' . phpversion() . 'rn' . 'MIME-Version: 1.0' . 'rn' . 'Content-Type: text/html; charset=UTF-8' . 'rn';
// Activation link
$activate_link = activation_link .'?email=' . $email . '&code=' . $code;
// Read the template contents and replace the "%link" placeholder with the above variable
$email_template = str_replace('%link%', $activate_link, file_get_contents('activation-email-template.html'));
// Send email to user
if(mail($email, $subject, $email_template, $headers)) {
$mailed = 1;
} else {
$mailed = 0;
}
return $mailed;
}
$code = '123456789';
$email = '[email protected]'; // I replace with my email address
$mailed = send_activation_email($email, $code)
?>
<h1>TESTING EMAIL</h1>
<?php
if($mailed == 1) {
echo "Mail Sent."; // Page tells me this...
} else {
echo "Mail FAILED";
}
?>
</body>
</html>