So something interesting I encountered while working on my site. I use Xampp on a mac OXS Lion to run my website. And I have mail() functions in my code that never worked (sent outgoing mail) before while I was connected to my home internet connection (Verizon Fios).
However, I was recently at a local hospital and logged onto the internet through what seemed to be an unsecure internet connection. While I was working on my site, all of a sudden the mail() functions started working and sending mail... But, when i got back home, it did not work anymore!
How can I figure out what was different, so that I can change some settings maybe in php.ini or maybe my computer configuration, so that I can get it to send mail, like it was doing at the hospital. I am trying to figure it out... any ideas?
Here is the mail header from the email sent to my gmail account:
I x-ed out my ip address... and y-ed out the "received by".
Delivered-To: myemail@gmail.com
Received: by yy.yy.yyy.yyy with SMTP id wx8csp106470vdb;
Fri, 6 Apr 2012 10:59:28 -0700 (PDT)
Received: by 10.224.116.6 with SMTP id k6mr10527899qaq.91.1333735167849;
Fri, 06 Apr 2012 10:59:27 -0700 (PDT)
Return-Path: <nobody@my-macbook-pro.local>
Received: from my-MacBook-Pro.local ([xxx.xxx.x.xx])
by mx.google.com with ESMTP id es10si7285733qab.33.2012.04.06.10.59.27;
Fri, 06 Apr 2012 10:59:27 -0700 (PDT)
Received-SPF: neutral (google.com: xxx.xxx.x.xx is neither permitted nor denied by best guess record for domain of nobody@my-macbook-pro.local) client-ip=xxx.xxx.x.xx;
Authentication-Results: mx.google.com; spf=neutral (google.com: xxx.xxx.x.xx is neither permitted nor denied by best guess record for domain of nobody@my-macbook-pro.local) smtp.mail=nobody@my-macbook-pro.local
Received: by my-MacBook-Pro.local (Postfix, from userid 4294967294)
id 8FF04156E2F; Fri, 6 Apr 2012 13:59:27 -0400 (EDT)
To: myemail@gmail.com
Subject: You Requested a New Password
From: admin@mysite.com
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1
Message-Id: <20120406175927.8FF04156E2F@my-MacBook-Pro.local>
Date: Fri, 6 Apr 2012 13:59:27 -0400 (EDT)
<div>
This is the email notification to reset your email address!
</div>
Last edited by Juniper747; 04-10-2012 at 02:51 AM..
I use Xampp on a mac OXS Lion to run my website. And I have mail() functions in my code that never worked (sent outgoing mail) before while I was connected to my home internet connection (Verizon Fios).
in this case I’d use the SwiftMailer or PHPMailer libraries to reliably send emails (or at least get a decent error message)
PS. Mac OS X comes with PHP & Apache installed. and there is also the MacPorts system to get you the latest version of PHP/Apache/MySQL/…
__________________
please post your code wrapped in [CODE] [/CODE] tags
in this case I’d use the SwiftMailer or PHPMailer libraries to reliably send emails (or at least get a decent error message)
PS. Mac OS X comes with PHP & Apache installed. and there is also the MacPorts system to get you the latest version of PHP/Apache/MySQL/…
Not a bad solution... but looks like installing such libraries would require me to change my code temporarily to add certain classes etc. just to send emails.
But, I do not want to have to change my code... Like I said it worked perfectly at the hospital (likely due to an unsecure ISP), so I need to figure out how to change my computer settings to have the same effect while I'm connected to my home ISP.
I'd suggest that its a simple access configuration in your home router. According to this, it was sent out by my-macbook-pro.local, and that would be consistent with a requirement to configure your own sendmail.
I'm not sure how it would be done in a mac, but you need to see if its queued up and sent from your machine. PHP cannot determine this (it can determine if the sendmail is valid, but cannot tell if it went anywhere), so you want to see if the actual email is sent and dropped by your host.
I'd say it could be a simple spam block, but since it works via one network and not the other, this would indicate that the cause is the network itself.
Needless to say, this hasn't actually a thing to do with PHP itself from the looks of it.
Thank you... that's great advice, and I agree, seems like it would be a simple security measure by the ISP or router.
So how would I "see if its queued up and sent from your machine"? I'm pretty sure it was sent by my machine, I mean, where else would it be sent from since localhost is set up on my macbook?
I can definitely access my verizon fios router, but which configuration would I need to change?
Check your port configs. Mail typically needs 110 and 25 open for POP3 and SMTP, and 143 for IMAP. SSL versions are 465, 585, 993, 995. I wouldn't be surprised if these are closed.
As for checking, if the router has a logging feature, see if you can sendmail (even from the command line is sufficient), and check to see if an event is triggered indicating it has blocked or dropped. While I could probably play around with a router long enough to do what I need, I'm not a network specialist so I'm afraid I cannot really advise generically how to fix the issue. You may be able to contact your ISP support as well and let them know you are trying to test sendmail functionality to see if they can walk you through it.
So I went into my router and created a new port forwarding rule using the ip address of localhost and giving it the port 25 (which is the default defined in the php.ini file for my localhost server): Here's a screen shot?
Have you opened 465 as well?
Like I said, i can fumble myself through a router config, but I can't really help when it comes to walking someone through. You should contact your ISP to get their support team to help you open any necessary ports. Even once that's done, there is no guarantee that it will allow you to send as it could still be blocked at the ISP level. All this would do is eliminate your home network as the cause.
So I just got off the phone with my ISP and they said that they allow emails through the following ports:
For SSL:
POP 995
SMTP 465
For non-SSL
POP 110
SMTP 587
So... I'm pretty sure localhost php uses smtp, and I do not think that the emails are getting stopped at the router but rather at the ISP server. So my question is, where/how do I change the port to either 465 or 582? Is it in my php.ini file? (note that I'm running on a Mac).
Last edited by Juniper747; 04-11-2012 at 06:53 PM..
You can set it in php.ini, and restart apache to take effect.
It can also be provided inline with an ini_set('smtp_port', 582);, or by reconfiguring sendmail as the fourth parameter in the mail() function.
You can set it in php.ini, and restart apache to take effect.
It can also be provided inline with an ini_set('smtp_port', 582);, or by reconfiguring sendmail as the fourth parameter in the mail() function.
Not sure how you would do this in a mac. On Windows you can modify the php.ini and provide the port directly. I don't know if sendmail has a runtime call to let it change its port (I would think so, but the man page I found doesn't indicate that a runtime config exists).
In linux, you can modify the sendmail.cf file to change the smtp to the port required, which you should copy before attempting. There will be a daemon configuration indicating that SMTP is used; that can be changed to use the port in use.
On a MAC I'd assume there is probably a gui configuration for this.
Geez.... This looks like it might be more trouble than it's worth!
I may be better off just going back to that hospital with the insecure Internet connection to test out my mailing functions! Especially since I am just testing my site on my local computer... Then, once I'm ready to go live with my site and move it to a real server like rackspace, I assume their techs would help me set everything up as far as emailing etc..?
Geez.... This looks like it might be more trouble than it's worth!
I may be better off just going back to that hospital with the insecure Internet connection to test out my mailing functions! Especially since I am just testing my site on my local computer... Then, once I'm ready to go live with my site and move it to a real server like rackspace, I assume their techs would help me set everything up as far as emailing etc..?
I'd say to not even worry too much about it. You know the mail works. I myself do not allow mail to move through my home machines even from testing, so I develop on the assumption it will work. I test it in a live environment after the fact. I don't actually make explicit calls to the mail function though, I wrap it into an object so I can adjust it from a central location. That way if mail is disabled I could manually send mail through sockets instead, call an IMAP or whatever. All I have to change is the one class that does this lifting and away I go.