6

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);
Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
Pank
  • 13,800
  • 10
  • 32
  • 45
  • 3
    See here: http://stackoverflow.com/questions/112190/php-ini-smtp-how-do-you-pass-username-password – Sean Carruthers Feb 24 '12 at 12:04
  • You can also consider using a library that has done the hard work of abstracting the intricacies of sending email away (http://swiftmailer.org/) – F21 Feb 24 '12 at 12:21
  • I am using XAMPP on Linux OS, so below script will work ? SMTP = mail.yourserver.com smtp_port = 25 auth_username = smtp-username auth_password = smtp-password sendmail_from = you@yourserver.com – Pank Feb 24 '12 at 12:38

1 Answers1

5

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.

Janos Pasztor
  • 1,265
  • 8
  • 16