How to set smtp username and password using ini_set

廉价感情. 提交于 2020-01-13 10:08:11

问题


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?.

$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 = 'xyz@gmail.com';
$subject = 'xx';

$headers = "From: abc@xyz.com\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","abc@xyz.com");
mail($to, $subject, $message, $headers);

回答1:


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.

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.



来源:https://stackoverflow.com/questions/9430412/how-to-set-smtp-username-and-password-using-ini-set

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!