php 如何使用ini_set设置smtp用户名和密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9430412/
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
How to set smtp username and password using ini_set
提问by Pank
This is my script to send a html mail.But after executing this script, I did't get mail.I don't know how to set username and password using ini_set("SMTP","smtp.xyz.com");? Is their any simple way to set SMTP without using any external library files?.
这是我发送html邮件的脚本。但是执行这个脚本后,我没有收到邮件。我不知道如何使用ini_set("SMTP","smtp.xyz.com");设置用户名和密码; ? 他们有什么简单的方法可以在不使用任何外部库文件的情况下设置 SMTP 吗?
$name=$_POST['name'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$messege="Dear Webmaster,<br /> An user sent query.<br /> Query: <br/> ".$_POST['messege']."<br /><br /><br /> <b>User Contact Detail:</b><br />Name:".$name."<br/> Email:".$email."<br />Mobile:".$mobile;
$to = '[email protected]';
$subject = 'xx';
$headers = "From: [email protected]\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";
ini_set("SMTP","smtp.xyz.com");
ini_set("smtp_port","25");
ini_set("sendmail_from","[email protected]");
mail($to, $subject, $message, $headers);
采纳答案by Janos Pasztor
As you may read in the PHP manual, the SMTP functionaliy for PHP is only available on Windows and it only has very basic functionality. If you need to use it on Linux and / or need username and password authentication, SMTPS, etc you will need to use libraries like SwiftMailer, PHP Mailer, etc. or you need to set up an external SMTP server on your own host like Exim.
正如您在 PHP 手册中所读到的,PHP的 SMTP 功能仅在 Windows 上可用,并且只有非常基本的功能。如果您需要在 Linux 上使用它和/或需要用户名和密码身份验证、SMTPS 等,您将需要使用SwiftMailer、PHP Mailer等库,或者您需要在自己的主机上设置一个外部 SMTP 服务器,例如Exim.
You should, however, not attempt to set up an SMTP server unless you are experienced in such matters, or you will make your server a nest for spammers in a matter of days.
但是,除非您对此类问题有经验,否则不应尝试设置 SMTP 服务器,否则几天后您的服务器就会成为垃圾邮件发送者的巢穴。