0

I have a php application I have running on my Xampp localhost. It has a user registration via email service, whereby a new user will register via email, but the account will not be active till activated by clicking on an email link sent to the email the user registered with.

I send email as follows:

<html>
<head>
   <title>Sending email using PHP</title>
</head>
<body>
   <?php
   $to = "user@yahoo.com";
   $subject = "This is subject";
   $message = "This is simple text message.";
   $header = "From:user@GMail.com \r\n";
   $retval = mail ($to,$subject,$message,$header);
   if( $retval == true )  
   {
      echo "Message sent successfully...";
   }
   else
   {
      echo "Message could not be sent...";
   }
   ?>
</body>
</html>

The email doesn't get sent. Is there something that I need to do before I can send email from a test website, or what is it I'm doing wrong?

Thank you all in advance.

Program-Me-Rev
  • 6,184
  • 18
  • 58
  • 142
  • 1
    What does `$retval` return? What error messages are being shown? Need more information here. I would use something like http://swiftmailer.org/ instead. – Edward Mar 30 '15 at 07:04
  • use phpmailer which is good for mail service in PHP –  Mar 30 '15 at 07:07
  • Sending emails can be one of the most complex tasks you can do in programming these days. See http://blog.codinghorror.com/so-youd-like-to-send-some-email-through-code/. Please try to research a little more into the topic and tell us in more detail how your system is set up and where exactly it seems to hang. – deceze Mar 30 '15 at 07:18
  • Which platform are you on? Sending emails via `mail()` is different between Windows and UNIX'y OS. – Ja͢ck Mar 30 '15 at 07:20
  • do you have any errors in your log? – Wikunia Mar 30 '15 at 07:39
  • none. No errors - @Wikunia – Program-Me-Rev Mar 30 '15 at 07:41
  • If you are on dev state, make sure you always set `error_reporting(E_ALL)`. Take a look in my answer [here](http://stackoverflow.com/a/28588957/2441442) and [here](http://stackoverflow.com/a/28905088/2441442), maybe this is the reason. – Christian Gollhardt Mar 30 '15 at 08:44

0 Answers0