PHP邮件()函数替换


PHP mail() function replacement?

当我更改提供程序时,我总是要让sendmail正常工作,这真的很麻烦。

我的PHP代码中有没有免费的提供者可以用来发送相同的变量,比如注册验证的密钥码之类的?

我试着在谷歌上搜索,但我只找到了有表单生成器的东西,这不是我需要的。

我使用PHPMailer非常成功。

目前Swift Mailer是PHP最好的邮件解决方案之一。它是高度模块化的,可以轻松配置以满足您的需求。您可以定义多个传输(例如在配置文件中),并在更改提供程序时使用所需的传输。

以下是文档中的一个示例:

require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
  ->setUsername('your username')
  ->setPassword('your password')
  ;
/*
You could alternatively use a different transport such as Sendmail or Mail:
// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
// Mail
$transport = Swift_MailTransport::newInstance();
*/
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
  ->setBody('Here is the message itself')
  ;
// Send the message
$result = $mailer->send($message);

您需要的是一个经过身份验证的传出SMTP服务器,这样您就不用使用主机,也不必每次都更改详细信息。

看看AuthSMTP(还有很多其他网站提供这一功能),然后使用PHPMailer或Swift Mailer之类的东西来发送带有身份验证的电子邮件。

问题是,许多ISP会阻止端口25(默认smtp)上与自己服务器以外的服务器的连接。与垃圾邮件屏蔽等有关。