I am getting an error while sending a mail from a form
Failed to connect to mailserver at “mail.yoursite.com” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\xampp\xampp\htdocs\send.php on line 8
Warning: mail() [function.mail]: SMTP server response: 550 ACCESS DENIED in C:\xampp\xampp\htdocs\send.php on line 9
Message delivery failed…
here is the code
mail.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="send.php" action="POST">
Enter Name : <input type="text" name="name" />
Enter E-Mail : <input type="text" name="email" />
Enter Subject: <input type="text" name="subject" />
Enter Message: <input type="text" name="mess" />
<input type="submit" name="Submit" />
</form>
<?php
?>
</body>
</html>
send.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$body = $_POST['subject'];
$message=$_POST['message'];
//ini_set("sendmail_from","name@yoursite.com");
//ini_set("SMTP","mail.yoursite.com");
mail("name@yoursite.com", $name, $message, "From :$from");
if (mail('nishantmshah@gmail.com', $name, $body, $message, "From :$from")) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
You’re using a win32 version of php and its smtp-implementation of mail(). It’s a tiny little MTA that can’t do authentication of any kind. If the smtp server you’re trying to relay the email to requires you to authenticate mail() will fail.
Either use (and configure) sendmail for win32. Or a mailer class/library that implements authentication, e.g. SwiftMailer.
btw: Xampp bundles the mercury smtp server. In its default configuration it accepts emails from local php scripts. But then you have to configure mecury to relay the emails to another MTA .