Building a simple php Mail class
Other, similar libraries don't require you to pass everything to the constructor. What if you want to send an email to more than one person? You should be able to call $mailer-&gt;setTo() more than once.

For now, I would suggest getting rid of the constructor entirely, and calling the setters manually as needed. After all, if you're planning on doing the entire operation in one call then you might as well write a function instead of a class.

If you're going to implement setter methods then you should make your properties private or protected so they can't be changed manually by whoever is using your class. Usually, the setters are implemented so you can validate input before setting them, for example, 

public method setTo($email){
    if(filter_var($email, FILTER_VALIDATE_EMAIL)) $this-&gt;toEmail = $email;
    else $this-&gt;lastError = "Invalid to email: {$email}.";
}


Now you can prevent the user from manually setting $mail-&gt;toEmail by marking it as private, thus, forcing the input to be validated by your setter.



You're not using your toName parameter and you're only allowing a single receiver. Check out the manual and you'll notice that you can have multiple recievers and you can specify a name for each one in the following format:


  User &lt;user@example.com>, Another User &lt;anotheruser@example.com>


Therefore, you should have an array for your toNames and another array for your toEmails.

public method setTo($email, $name=""){
    if(filter_var($email, FILTER_VALIDATE_EMAIL)){
        $this-&gt;toEmail[] = $email;
        $this-&gt;toName[] = $name;
    }else $this-&gt;lastError = "Invalid to email: {$email}.";
}


Then, in your send function...

$to = "";
foreach($this-&gt;toEmail as $k=&gt;$v){
    if(!empty($this-&gt;toName[$k])) $to .= "{$this-&gt;toName[$k]}&lt;$v&gt;,";
    else $to .= "$v,";
}
$to = rtrim($to, ","); // trim off trailing comma




If you're not sending an HTML email you should wordwrap your $message parameter at 70 chars. (You can create a variable to determine if the email will contain HTML).

if(!$this-&gt;isHTML) $message = wordwrap($message, 70, "\r\n");


If it is HTML you have to let the client know by adding these headers:

$headers .= 'MIME-Version: 1.0'."\r\n".
    'Content-type: text/html; charset=iso-8859-1';


You can also carbon copy someone with this header:

'Cc: birthdayarchive@example.com'




Anyway, you're on the right track, but make sure you read the manual to see what other cool stuff you could be doing.