I have a local server which host PHP applications. My applications send emails to different addresses. However, I am noticing a problem that I am unable to figure out. It send emails to internal addresses but it won't send messages to external addresses.
I also have an exchange server on the same network. so for example I have these 2 "internal domain"
domain1.com
domain2.com
if I execute this php function from my application it gets delivered with no problem
mail("name#domain1.com","Test Subject","Test message");
However, if I try sening a message to gmail, yahoo or any external domain it does not send it
mail("name#gmail.com","Test Subject","Test message");
My server is running on Windows 2008 Server R2 with PHP5.3.19 installed on it via IIS6
How Can I correct this issue?
mail() on Windows needs extra config in php.ini because Windows does not have Sendmail or anything similar.
The first is the SMTP setting which should point to your ISP's outbound server which is not necessarily the same server that you retrieve your mail from. When I worked in support there were a lot of issues like you describe because an inbound server will still accept mail, but only for the domains that are local to it.
The second is the sendmail_from setting, which is what the gimpy little mailer PHP wrote for the Windows distribution uses in every SMTP transaction regardless of what's in the headers. On *nix Sendmail will read the headers and get the From: address itself, on Windows PHP will always use what's in php.ini. If this is a "garbage" address like example#example.com or something with a non-existant domain many mail servers will reject it outright. What I recommend is to change it to something decent in PHP.ini as well as adding the following line to your mailing scripts:
ini_set('sendmail_from', $from_address);
Alternatively, just use PHPmailer since it simply works much better than PHP's horrid little mail() function.
Related
This is an issue I've encountered several time and haven't yet found a decent solution for:
Sending an e-mail from a webserver on e.g. "domain.com", to info#domain.com which is hosted on an external mail server e.g. Google Mail
In my case I always send from PHP over Apache and often on shared hosting, but I can imagine this is the same case on other frameworks.
These e-mails always seem to be delivered to the local mail server, even if I set the MX records on that server to point to the right external mail server.
A solution for this is to use an external SMTP server, but this isn't always easy when you're working with clients that either need to set-up a new e-mail account on their server and provide the SMTP details or sign-up for a third-party SMTP server.
What is the solution for this? Is there no way around SMTP?
Most emai/MTA server "autoconfigure" themselves. They guess list of local email domains (doimans with locally hosted mailboxes).
In sendmail case you can turn it off adding the following line in sendmail.mc:
define(`confDONT_PROBE_INTERFACES', `True')
Documentation : cf/README - confDONT_PROBE_INTERFACES
I have had the same issue many many times (in my case using PHP on a LAMP stack).
Try/check the following.
If you are using cPanel or similar, set the MX records to the external mailserver (Google apps etc).
Set up an SPF record to allow your hosting website to send email (this way no need to configure SMTP).
This may not be applicable but if you are using something like phpmailer. Set the property $mail->isMail(); so it tries to use your SPF allowed local mail() function to send the email. Sorry for going off into very specific advice, but might help in your particular situation.
Worth checking there are not similarly named local mailboxes on your hosting box.
Hope this helps!
I am trying to receive mails in my local server running XAMPP. I have Mercury and outlook configured and running according to this: http://system66.blogspot.in/2010/01/how-to-send-mail-from-localhost-with.html
My goal is that, I must be able to send a mail from xyz#somedomain.com to someaddress#localhost and I want to parse the received mail and store it in a MySQL DB.
I saw many references telling how to send mail from localhost (using gmail's smtp server using sendmail) but I dont find any resource telling me how to receive mail from anyone onto my local computer. Once I receive the mail to my PC, I can parse it and store it in DB. The only problem is getting the mail. Please help me out.
PS: I have configured php.ini and sendmail.ini files for doing the operations.
Firewalls are disabled and ports are available.
If you dont understand my question, imagine my pc as a mail server which is trying to get the mail sent to xyz#myserver.com
UPDATE : You need to configure DNS for your mail server. Take a look at this. Hope it would help.
You need to open port in your router & PC firewall in order to get requests from outside and a mail server.
I am trying to send an e-mail from localhost but am getting the error:
Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set().
Does this mean i need to set up a local mail server?? and if so how and which one is easiest.
Thanks in advance
Paul
This is what I use, but it's for testing purposes only:
http://www.toolheap.com/test-mail-server-tool/
There's almost no configuration, and I got it to work right out of the box (on Win7) after failure with several other mail servers. It does not send the actual mail, but stores it as an .eml file. This is great for testing mailing lists for instance, where you don't really want to send the 2000 emails, but want to get a realistic result from your application.
It might look like garbage, but it's been working great for me.
Yes, it does, and if you want to send mail to an outside email address (and not a user local to the system, it is annoyingly difficult).
Most hosting companies (e.g. GoDaddy) have this setup for you, so PHP's mail() function works without you needing to do anything.
If you're configuring it on your own system, you might want to consider (a) configuring sendmail to use an alternate SMTP gateway (I frequently use Gmail) or (b) a complete alternative to sendmail (Zend Mail looks promising.)
If you are using Linux, there is usually no need to set up a a mail server,
If you are using Windows, yes, you do need to set up a mail server
If you are interested in just sending mail, you can by SMTP protocol use any SMTP server. Here is a tutorial to setting up PHP to use a remote SMTP server.
Yes, you need a mail server to be able to send mail, but even if you do, you are not going to be able to send to addresses outside of you local network as mail from your computer will be blocked by all recipients for spam reasons.
You could use the pear mail function to connect to an external smtp providor like gmail to send the mails for you. More info here and here.
smtp4dev is in my opinion the best tool for capturing local SMTP traffic on Windows.
It listens SMTP on localhost port 25 and pops up a notification every time a new mail is posted (it doesn't actually forward the mail to its recipient). You can then open the message in your favorite mail agent or save it to a file.
I'm building a site on my home computer using MAMP. The code I'm using employs the PHP mail() function to send emails, but whenever I test it, the mails aren't getting sent.
My computer is connected to the net, but I'm wondering if there's something about local hosting that prevents mails from getting sent. I'm not getting any kind of error message.
Any ideas?
PHP can send mail in one of two ways.
The first, and the default on non-Windows systems, is to use the local mail transfer agent installed on the system. This would be "sendmail" or an application compatible with it, the most popular probably being postfix.
The other is to connect via SMTP to some mail server.
You will either need to install a mail transfer agent on your local system (and set it up correctly), or edit PHP's configuration to specify an SMTP server address and port.
Yes, there are things that could block locally hosted mail. For one, your ISP could block SMTP to servers other than the ISP. ask your ISP support if they block SMTP... Or try telexing so someone's MX port 25 and do you get a response?
If your ISP blocks smtp you can still send the mail, but first you must relay that email through a hosted email server like your ISP mail server. This process is called 'smart hosting' and you can search for more info.
Even if you are not blocked on port 25, many sites will refuse or lose smtp traffic that originates from a dynamic or residential IP address, so again the smart host suggestion.
Also I suggest not using the built in mail() function in PHP... Use something that replaces and improves it like http://pear.php.net/package/Mail or http://sourceforge.net/projects/phpmailer/. Again, use the SMTP method as it is way more reliable than direct sending or calling Sendmail.
It is important to confirm this problem, doing SMTP manually over telnet. That way you isolate the problem from PHP. I did ISP support for years and saw this question lots. Most people setup php and mail correctly but get stuck on a background network issue with SMTP.
If you have Wireshark installed, it can record network traffic and you might see the actual SMTP traffic, for example the remote server may be refusing your connection. Wireshark is helpful but not required to solve this though. Good luck.
You need to setup SMTP server in order to be able use mail function, or you can use PHPMailer class, with it you can avoid using mail function and setup problems, PHPMailler need socket extension to be loaded in order to function correctly.
I'm developing a Web application with PHP 5.3.3.
I want it to send confirmation e-mails automatically.
I don't have a domain name yet.
I'm using Windows XP.
I don't have PEAR's Mail package.
I have hMailServer and is the mail server I want to use to send the e-mails.
My questions are:
Can I send e-mails without a domain name? (Is it absolutely necessary? I just want to test the application for the moment.)
If a domain name is necessary, do I also need to host the application with a Web Hosting Service Provider? Can I do it from my computer?(Remember, I just want to test the application.)
Do I absolutely need the PEAR's mail package? or can I simply use the mail() function?
I'm clueless about what I should do. I've made my research, I understand the parts but I can't make sense of the whole, I mean what resources are necessary and how to put it together. I've never developed any application that sends e-mail before. Please, help me.
Yes. You can set your "from" address to whatever you want. (Though note, the recipient server might detect it's forged and reject it.)
You can host from you computer, just make sure your network is not blocking port 25 outbound.
mail() alone will suffice as long as you have a local SMTP server that will handle your messages. (I'm assuming that's what the hMailServer product is.)
First off, if you're running Windows as your server, you need to configure how your e-mails will be sent (SMTP server). Go to this section in your php.ini file. Change localhost to an SMTP server you can use from your network (either the IP address of your hMailServer OR sometimes you need to purchase one to use like http://www.smtp2go.com/).
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
Second, you use the mail(...) function in php (including the ability to send HTML mail). That's it.
Yes, you can. I believe your emails will show up with your server's DNS by default, but you can set the from: header to whatever you want. However, if you change the from: header, be warned that your emails are likely to get picked off by spam filters.
You need some special server configuration to use the php mail() function - I haven't tried setting it up myself, but I know that a basic local apache / php install won't have the capacity to send emails. Pretty much every paid web server should have it set up properly, though.
No. You can send regular and html emails with the generic mail() function.