0

Below is the full code of my form processing PHP page:

$success = false;

if (isset($_POST['name'])) {

    $name = $database->clean_input( $_POST['name'] );
    $company = $database->clean_input( $_POST['company'] );
    $email = $database->clean_input( $_POST['email'] );
    $phone = $database->clean_input( $_POST['phone'] );
    $content = $database->clean_input( $_POST['content'] );

    $database->query(" INSERT INTO messages (name,company,email,phone,content) VALUES ('" . $name . "', '" . $company . "','" . $email . "', '" . $phone . "', '" . $content . "') ");

    $message = 'FROM: ' . $name . '\r\n\r\nCOMPANY: ' . $company . '\r\n\r\nEMAIL: ' . $email . '\r\n\r\nPHONE: ' . $phone . '\r\n\r\nCONTENT: ' . $content;
    $message = wordwrap($message, 70, "\r\n");

    $headers = 'From: no-reply@censored.com' . "\r\n" .
        'Reply-To: contact@censored.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

    if(@mail('me@censored.com', 'censored.com message from ' . $name, $message, $headers)) {
        $success = true;
    }
    else
      echo '<p>Error: Your request could unfortunately not be processed, please use another contact method or try again later.</p>';

}

After this is executed, $success = true; so it seems the mail was successfully sent, but 20mins later I've still received nothing in my inbox.

I used I the same code on a live site in the past and it did work. I'm now running this on localhost with XAMPP and I'm wondering if it's not a config issue.

I'm a bit lost how to debug this further tbh.

EDIT:

I'm using the latest version of XAMPP and running on Mac OS X

Juicy
  • 11,840
  • 35
  • 123
  • 212
  • 1
    Are you using Windows on this local machine? I don't think Windows has support for natively sending emails without the aid of some third party software. One alternative is to use something like [phpMailer](http://phpmailer.worxware.com/) though I appreciate this might not be the solution you're looking for. – Dale Aug 24 '14 at 15:18
  • @Dale No it's Mac OS X – Juicy Aug 24 '14 at 15:20
  • 1
    OK I will have to gracefully step away from this conversation, I have very little knowledge of Mac and their intricacies :) I [hope this article](http://jonathonhill.net/2013-04-19/send-mail-using-php-on-mac-os-x/) helps – Dale Aug 24 '14 at 15:21
  • 1
    Mailing from a local computer normally doesn't work, as you probably have a dynamic (and blocked for sending mail...) e-mail address, your mail probably doesn't even pass your ISP and if it does, it will probably be stopped on the way to the destination or on the destination mail server. Too much spam. If you use a mailer library like Swift Mailer, you can easily use an external SMTP service like for example gmail to send your mail. – jeroen Aug 24 '14 at 15:23

2 Answers2

2

PHP's mail() function rarely works out of the box unless you have a mailserver set up. You will have to install one then configure PHP to use it. Here's a tutorial I just Googled.

Community
  • 1
  • 1
I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
  • Not likely to be the problem; as `mail()` has returned `true`, *something* has accepted the message for delivery. Still plenty that could go wrong though :-) – jeroen Aug 24 '14 at 15:29
  • @jeroen You're right, PHP accepted it for delivery to the mailserver. Doesn't mean there's actually a mailserver to send it to. From the manual: /It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination. / – I wrestled a bear once. Aug 24 '14 at 15:32
1

You have to buy a mailserver to do this thing.XAMPP and other local server programs doesn't provide mailserver as far as i know.

garry towel
  • 59
  • 1
  • 10