php 验证php邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10455469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Authentication php mail
提问by acctman
I'm using mailto send e-mails from PHP. It's working fine, but now I need to use a more secure mail server.
我正在使用mail从 PHP 发送电子邮件。它工作正常,但现在我需要使用更安全的邮件服务器。
I need to connect with the mail server using the following configuration:
我需要使用以下配置连接邮件服务器:
smtp: "mail.newserver.com"
port: "25"
timeout: 60
auth: yes
user: name
pass: word
How should I change my code below so it works with above configuration?
我应该如何更改下面的代码,使其适用于上述配置?
$to = $SendTo;
$headers = "From: <info@---->" . "\r\n" . "X-Mailer: php";
$subject = "Website Contact : " . $uxGlobalLocation;
$body = $Bodycopy;
if (mail($to, $subject, $body, $headers)) {
header ('Location: /index.php?option');
exit();
} else {
echo("<p>Message delivery failed...</p>");
}
采纳答案by WojtekT
Actually mail function doesn't provide authentication functionality. Your have to use Mail class from Mail Pear package. See here for an example: http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
实际上邮件功能不提供身份验证功能。您必须使用 Mail Pear 包中的 Mail 类。请参见此处的示例:http: //email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
回答by álvaro González
The builtin mail()function does not provide any sort of authentication. You need to use a third-party library that offers SMTP authentication. Popular choices include:
内置的mail()函数不提供任何类型的身份验证。您需要使用提供 SMTP 身份验证的第三方库。流行的选择包括:
- PHPMailer
- Swift Mailer
- PEAR Mail(has not been updated for a while)
You can also search for Composer packages at Packagist.
您还可以在Packagist搜索 Composer 包。

