Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

php - PHPMailer v. mail() for a simple Contact Form

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 new contact form.

The form is simple:

Your name:
Your email:
Subject:
Body:

I have around 2,000 visitors per day and receive about 10 submissions per day, so I don't need anything too fancy. =)

Miscellaneous questions in my head:

  • Is PHPMailer going to better protect my Contact Form from CC: injection (major concern)? I already know the anti-spambot display:none CSS trick.
  • Will PHPMailer save me the step of having to write an email_validator() function?
  • Will PHPMailer save me any other time of having to write any custom functions?

Thanks! With any luck, I'll be answering questions soon. Lol

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is all I could think of in one sitting, forgive me if there are any glaring omissions.

Advantages to using PHP's built-in mail function, no external library/wrapper:

  • You don't need anything outside of PHP.
  • You don't need to learn a new API.
  • You don't have to worry about a PHP upgrade or such breaking the script.
  • You don't have to worry about an updated version not working on your PHP installation.
  • You don't have to worry about potential security vulnerabilities as a result of using that script.
  • If it's a simple task, you'll be done in a few minutes.

Advantages to using an external library/wrapper:

  • If you need to introduce more complexity into your emailing, you can do so quite easily. Adding attachments, inline images and such are not much fun using PHP plain mail function. External libraries (at least the good ones) have a more OOPish API. Adding an attachment can be as easy as $message->addAttachment($file); without having to play around with headers, etc.
  • External libraries better hide the ugly complexities of tasks such as adding attachments, character encodings and inline images.
  • Using a library now will save you the hassle of having to learn it in the future when you do need the additional complexity/functionality.
  • External libraries probably (I'm really not sure which ones, and to what extent) address certain vulnerabilities that PHP's mail does not.

If I can think of anything else, I'll be sure to add it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...