0

I have the following function:

    public function retrieve_password()
    {
// multiple recipients
        $to  = 'mr@businesspower.dk' . ', '; // note the comma
        $to .= 'mr@businesspower.dk';

// subject
        $subject = 'Birthday Reminders for August';

// message
        $message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
        $headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
        $headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
        $headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
        $headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
        mail($to, $subject, $message, $headers);

    }

Now i know that from my local machine it can sometimes have problems sending so right now it is online on my server.

However when i send an email using this function the email never arrives.

I know that sometimes you need smtp and setup a user that the e-mail should be sent from but i am not quite sure how to do it and if it is even needed?

Can someone point me in the right direction?

Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364

1 Answers1

3

Unfortunately, when using the mail function in PHP it doesn't actually give many errors and isn't a very good function to use.

The issue could have derived from an incorrectly setup sendmail server or it could be that the server is localhost and hasn't been configured to send mail outside of the local server.

Your best bet would be to use a php class/library such as PHPMailer. This way you can connect to an SMTP server and it is also alot easier to debug rather then using the mail function.

There are so many variables which could be causing your issue. A few are listed below.

Hope this helps.

Sharpy310
  • 113
  • 11