I've created a PHP Mail class with the method of registerNewUser. Basically as my title says the method is returning true, when it should be returning false because i'm not receiving an email. Can someone explain if i'm doing something wrong? (Please do not comment on me sending the user an unencrypted password. This unencrypted password is a 25 character alpha numeric randomly generated password. Security is not an issue here) I do not wish to use some type of framework. I want to code this by hand, so please don't tell me to use PHPMailer or anything of that sort.
Edit: I'm figuring out that I'm needing to set up XAMPP to send outgoing Emails using SMTP. This question is not a duplicate as every other answer on every other question is windows based, and even then doesn't provide a step by step instruction on how to set up SMTP on a XAMPP localhost server.
Here's the code:
<?php
class Mail {
private $headers;
public function __construct() {
// Setting Up Mail Headers
$this->headers = "MIME-Version: 1.0 \r\n";
$this->headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
$this->headers .= "From: Admin @ NAStepsOnline <no-reply@NAStepsOnline.com>\r\n"."X-Mailer: php";
}
/**
* @desc Mails the User from registration email.
* This function should only be called through
* registerNew() within the user.class file
* @param str $userName First Name of the user
* @param str $userEmail Email address of the user
* @param str $userPass Password of user (UNENCRYPTED)
* @return bool True = Mail Sent Sucessfully
* False = Mail Not Sent
*/
public function registerNewUser($userName, $userEmail, $userPass) {
// Define Subject Line
$subject = "Thanks " . $userName . " for Registering On NAStepsOnline.com";
// Setting Up Message to the User
$msg = "<html><body>";
$msg .= $userName . " Thanks for registering at NAStepsOnline.com<br><br>";
$msg .= "Here is your password (case sensitive): " . $userPass . "<br><br>";
$msg .= "Please use the login form to login.<br>";
$msg .= "To assign a sponsor to your account please visit the Profile Settings page and click on My Sponsor.<br>";
$msg .= "If you have any problems please contact us using the Contact Us page.<br><br>";
$msg .= "Thanks,<br>The Team @ NAStepsOnline.com";
$msg .= "</body></html>";
// Mailing the user Registration
$mail = mail($userEmail, $subject, $msg, $this->headers);
if($mail) {
return true;
} else {
return false;
}
}
}