How to send mail in WampServer using hMailServer

914 Views Asked by At

I have mail function in php which looks like:

<?php
  $admin_email = "[email protected]";
  $email ="[email protected]";
  $subject = "hellow ord";
  $comment = "cmt";

  try{
    $th=mail($admin_email, $subject, $comment, "From:" . $email);
    if($th)
      echo "gg";
    else    
      echo "error_message";
  }
  catch(Exception $e)
  {
    echo $e->message();
  }
?>

I have Wamp server to run it. I have configured hMailServer by seeing a post on Stack Overflow but when I run the above code I get:

Warning: mail(): SMTP server response: 530 SMTP authentication is required... 

Do I need to set up anything before using mail function?

1

There are 1 best solutions below

0
On

The PHP mail() function doesn't support smtp authentication, which generally results in an error when connecting to public servers like the one you are trying to connect to. With hmailserver installed, you still need to use a library like PHPMailer which you can autheticate with.

Follow the steps here to setup phpmailer with gmail: http://blog.techwheels.net/tag/wamp-server-and-phpmailer-and-gmail/

I've successfully sent email using gmail on (wamp/hmailserver/phpmailer).

<?php
  require_once ("class.phpmailer.php");
  $sendphpmail = new PHPMailer();
  $sendphpmail->IsSMTP();
  $sendphpmail->SMTPAuth = true;
  $sendphpmail->SMTPSecure = "ssl";
  $sendphpmail->Host = "smtp.gmail.com";
  $sendphpmail->Port = 465;
  $sendphpmail->Username = "[email protected]";
  $sendphpmail->Password = "gmail_password";
  $sendphpmail->SetFrom('[email protected]','blahblah');
  $sendphpmail->FromName = "From";
  $sendphpmail->AddAddress("[email protected]"); //don't send to yourself.
  $sendphpmail->Subject = "Hello!";
  $sendphpmail->Body = "<H3>Check out www.google.com</H3>";
  $sendphpmail->IsHTML (true);
  if (!$sendphpmail->Send())
  {
    echo "Error: $sendphpmail->ErrorInfo";
  }
  else
  {
    echo "Message Sent!";
  }
?>

Hope this helps others as well. Took me a few hours of googling and compiling answers from places while facing this issue.