PHPMailer v. mail() for a simple Contact Form

前端 未结 4 1596
星月不相逢
星月不相逢 2020-12-14 23:05

I am new to PHP, but have a decent grasp of things (have not learned classes yet).

The question:

Which to choose? PHPMailer or mail() for my

4条回答
  •  青春惊慌失措
    2020-12-14 23:48

    This will maybe not really answer all your questions, but it won't hurt either, I guess...

    Whatever you want to do, I would not go with mail() : sending a mail is not such an easy task, and using an existing library/framework will always be a good idea : it will solve many problems you probably have not even thought about -- even if you don't need to send lots of mails.


    About your specific questions, maybe other answers will say something else and/or get your more informations, but any "good" library created to send mails should deal with those kind of problems... Else, you should probably search for another library ^^

    Still, testing a couple of dumb non-addresses will allow you to be 100% sure ;-)


    Another solution to be quite sure is to check the source of the library ;-)

    In the source of version 2.2.1, you'll find stuff like this :

    class.phpmailer.php, function AddAnAddress, line 413, you'll see this :

    if (!self::ValidateAddress($address)) {
      $this->SetError($this->Lang('invalid_address').': '. $address);
      if ($this->exceptions) {
        throw new phpmailerException($this->Lang('invalid_address').': '.$address);
      }
      echo $this->Lang('invalid_address').': '.$address;
      return false;
    }
    

    And it seems this function is used by the other functions that add an address... So, I suppose there's some kind of email-addresses validation ;-)
    That'll answer at least one of your questions ^^


    PHPMailer is not the only solution that exists, btw ; there are plenty of others, like, for instance :

    • Zend_Mail
    • Rmail for PHP (Formerly known as HTML Mime Mail)
    • Swift Mailer

提交回复
热议问题