views:

300

answers:

4

Hi

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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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","[email protected]");
//ini_set("SMTP","mail.yoursite.com");
mail("[email protected]", $name, $message, "From :$from");
if (mail('[email protected]', $name, $body, $message, "From :$from")) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }
?>
A: 

The message SMTP server response: 550 ACCESS DENIED suggests to me that you should check your credentials for that server again. Your username, or password may be incorrect.

Jonathan Sampson
wheredo i have to mention the username, or password?
Josh
A: 

You need to install this PEAR Module if you wish to use authentication as it is not provided in the mail function of PHP.

Sending Mail from PHP Using SMTP Authentication - Example

<?php
require_once "Mail.php";

$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>
Shadi Almosri
Hi Shadi,Thanks for the code just wondering where do i find the smtp_username and password is it the one i use for login? Thanks once again.
Josh
If you're using XAMPP, then check the XAMPP control Panel and see if the Mercury mail server is running first, then let me know?
Shadi Almosri
no it wasn't running yet
Josh
Ok start the mail server and accept any windows notification (to allow it to access the ports) then retry your script.
Shadi Almosri
550 access denied
Josh
+1  A: 

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 .

VolkerK
A: 

basicaly if you are on a hosted server then sending an email with php is easy as drinking cold water.

if(mail('[email protected]','subject','content here i include sometime var_export($var,1)'))
 echo 'email send succefull';
else
  echo 'emaiol coudnt be send';

if you send this from your localmachine this will mostly fail because most server refuse requests like this. Then you have to use an external library for sending your email from a service like gmail.

streetparade