[英]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). 我是PHP新手,但对事物有很好的掌握(还没有学过课程)。
The question: 问题:
Which to choose? 选择哪个? PHPMailer or mail() for my new contact form.
我的新联系表单的PHPMailer或mail()。
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. 我每天有大约2,000名访客,每天收到大约10份提交,因此我不需要任何太过花哨的东西。 =)
=)
Miscellaneous questions in my head: 我头脑中的其他问题:
anti-spambot display:none CSS
trick. anti-spambot display:none CSS
技巧。 email_validator()
function? email_validator()
函数的步骤吗? Thanks! 谢谢! With any luck, I'll be answering questions soon.
运气好的话,我很快就会回答问题。 Lol
大声笑
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: 使用PHP的内置邮件功能的优点,没有外部库/包装器:
Advantages to using an external library/wrapper: 使用外部库/包装器的优点:
$message->addAttachment($file);
$message->addAttachment($file);
一样简单$message->addAttachment($file);
without having to play around with headers, etc. If I can think of anything else, I'll be sure to add it. 如果我能想到其他任何事情,我一定会加上它。
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. 无论你想做什么, 我都不会使用
mail()
:发送邮件并不是一件容易的事,使用现有的库/框架总是一个好主意:它会解决许多你甚至没想过的问题关于 - 即使你不需要发送大量邮件。
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 ;-) 尽管如此,测试一些愚蠢的非地址将让你100%肯定;-)
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 : 在2.2.1版的源代码中,你会发现这样的东西:
class.phpmailer.php
, function AddAnAddress
, line 413, you'll see this : class.phpmailer.php
,函数AddAnAddress
,第413行,你会看到:
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 ; PHPMailer不是唯一存在的解决方案,顺便说一下; there are plenty of others, like, for instance :
还有很多其他的,例如:
As Pascal MARTIN mentioned, sending an email isn't as straight forward and easy as some people just assume it is. 正如Pascal MARTIN所提到的,发送电子邮件并不像有些人认为的那样简单直接。 To answer your questions directly.
直接回答你的问题。 Yes PHPMailer does do some validation, but it's not super-advanced, but should be enough for your uses.
是的PHPMailer确实做了一些验证,但它不是超级先进的,但应该足以满足您的需求。 And PHPMailer will save you some time depending on what custom functions you will need.
PHPMailer将为您节省一些时间,具体取决于您需要的自定义功能。 Some things to consider though:
有些事情需要考虑:
In addition to just PHPMailer Zend_Mail is a good one to check out to (it's part of the Zend Framework ). 除了PHPMailer之外,Zend_Mail是一个很好的检查(它是Zend Framework的一部分)。 However that may be a bit much for a simple contact form.
然而,对于简单的联系表格,这可能有点多。
PHPMailer是我的选择,因为它允许我发送SMTP电子邮件到谷歌而不安装任何库或配置邮件服务器,这样我就不必担心垃圾邮件相关的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.