Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set smtp username and password using ini_set

Tags:

php

smtp

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 = '[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);
like image 629
Pank Avatar asked Feb 24 '12 12:02

Pank


1 Answers

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.

like image 76
Janos Pasztor Avatar answered Oct 14 '22 05:10

Janos Pasztor