Lunarpages Web Hosting Forum

Author Topic: Problem receiving mail sent by PHP mail()  (Read 1524 times)

Offline mithra

  • Newbie
  • *
  • Posts: 5
Problem receiving mail sent by PHP mail()
« on: January 28, 2019, 03:13:17 AM »
Hey guys,

I'm creating an account portal in PHP that does email address verification, but when then PHP script sends the email out TO any address belonging to ME hosted on Lunarpages, well... it never arrives.  But IF I use an external email, like yahoo.com, the email arrives just fine.  The PHP mail() function always returns a 1.

How is it possible that my server is blocking emails that I'm sending to myself?  I don't have Spam Assassin enabled.  Any feedback would be appreciated!

- Bob

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6429
Re: Problem receiving mail sent by PHP mail()
« Reply #1 on: January 28, 2019, 06:05:53 AM »
I seem to recall some discussion a while back about problems sending mails within a hosting account. I don't think it's outright banned, but there may have been some tricks to it. I have a contact form on my site which emails to my site-based mail addresses, and I don't recall having to do anything special. Just make sure the return and reply-to addresses are consistent and legal for your site, and I think that should be enough. My contact email "from" address shows as <account name>@<server>.lunarpages.com -- are you trying to insert an actual mailbox address? I think I just let mine default.
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline mithra

  • Newbie
  • *
  • Posts: 5
Re: Problem receiving mail sent by PHP mail()
« Reply #2 on: January 28, 2019, 06:42:40 AM »
Thank you for your reply!

Here is the function I wrote to send a confirmation email...

function EmailConfirmationCode( $email)
{
    $subject = "Your PlayerBionika email confirmaton key";

    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text; charset=iso-8859-1\r\n";
    $headers .= "From: noreply@playerbionika.com\r\n";
    $headers .= "Reply-To: noreply@playerbionika.com\r\n";

    $content .= "confirmaton key: ".$_SESSION["szEmailConfirmationKey"];

    $result = mail( $email, $subject, $content, $headers);
   
    echo( $result);
}

It's echoing a 1 for the return value as if SUCCESS, and I've tried every combination of sender/addressee, whether a defined mailbox on my domain (playerbionika.com) OR random names @playerbionika.com ( which default to my main inbox).. neither works.  Again, the code gets an email out to yahoo.com just fine, I just can't send mail to myself for some reason.  One would think there is a configuration or blacklist problem with my email server, rather than a code issue, but then again maybe my headers are badly formatted?  I'm trying the code on a Microsoft Azure web host at the moment and having the same problem...

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6429
Re: Problem receiving mail sent by PHP mail()
« Reply #3 on: January 28, 2019, 09:55:44 AM »
Is "noreply" a real email address on your site? I think the mail system may suppress fake "From" addresses. You might try adding a real "noreply" account (just ignore and flush anything that comes into it). Other than that, I don't see anything that jumps out at me, but then, mail handling is not one of my strong points.

http://php.net/manual/en/function.mail.php
« Last Edit: January 28, 2019, 09:57:59 AM by MrPhil »
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline mithra

  • Newbie
  • *
  • Posts: 5
Re: Problem receiving mail sent by PHP mail()
« Reply #4 on: January 28, 2019, 10:37:42 AM »
Noreply isn't configured but if you send mail to it it will go to my main inbox.  I've tried it with my main "real" email in those fields too and nothing gives.  In any case thank you for your help :)

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6429
Re: Problem receiving mail sent by PHP mail()
« Reply #5 on: January 28, 2019, 01:37:16 PM »
My point is that you may not be able to send from a fake address, within your site. Actually having a "noreply" email address might permit it (I don't know for sure). You might want to try it, as that's all I can think of.
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline mithra

  • Newbie
  • *
  • Posts: 5
Re: Problem receiving mail sent by PHP mail()
« Reply #6 on: January 29, 2019, 07:11:04 AM »
Just wanted to update...

I was able to get PHP mail() working reliably after migrating my website to MS Azure :/

I just had to modify THEIR php.ini to include

[mail function]
SMTP = mail.playerbionika.com

So.. I AM using the Lunarpages SMTP server (for the moment).. the original problem is still a mystery, I just guess there's some quirk with tiberius.lunariffic.com since it works *half* the time.

Migration ALSO solved my socket_sendto problem .. I think maybe Lunarpages has this locked down due to abuse potential, but I kinda need it to work in order to send notifications to my server. :/

Anyway, I think this is solved, I appreciate you having looked at this MrPhil!