cURLing to a remote server to send email - php

My hosting provider doesn't allow access to external SMTP mail servers. The problem is that some emails don't get sent using the internal server.
What are the dangers in posting data to a remote server to send emails?

You can post it by HTTPS if your provider does listen to your posted data.
If you are sure that nobody in your server's network catch your outgoing data, you can post it with normal http to your mail server (just simple php script) which then sends mail

I guess you what you mean is that you tried to use curl to send mails via remote servers and your host won't grant you usage of curl.
There is no inherent danger in sending mails but curl will give you a very powerful networking-tool and I guess that is what your host is not keen on handing over to his clients.

Related

Getting my web server to send an email on behalf of my mail server

So, I have a separate web server and mail server configured for the same domain (web.example.com & mail.example.com, each with different IPs). The reason I did this was so that I could use CloudFlare to deliver my web content while protecting my origin IP. I understand that my mail server's IP is exposed, this is alright for the time being.
The issue I am facing is that if an email originates from my web server (let's say for instance a user forgets their login details, and my web server triggers a recovery email to be sent)... this will expose my web server's origin IP in the headers of the email sent to the user.
What I need to be able to do, is either one of the following, I am also open to other suggestions:
1) Masquerade as the IP of web.example.com
2) Trigger an email to be sent from mail.example.com
Both servers have PostFix and Dovecot configured.
I am using PHP to trigger mails to be sent.

Using PHP to send mails from my organisation's email id?

So, I developed this web application which needs me to send emails to everyone (details in a mysql database), providing a unique set of user credentials. I have a virtual server on the University network where I am hosting my PHP based application, so it obviously doesn't have its own mail server/SMTP settings.
So, if I were to send out mails from a university network, I guess I should request the network admin for the SMTP settings for the university mail network and then use PEAR for it right?
I need to confirm this because it's kind of a big deal to make a request like that, and I myself have never used PHP to send mails 'from' an external email id not linked to the server.
Are there any alternatives to this?
Yes you can use PEAR::mail to send mails via SMTP server. However, if SMTP is configured on localhost you can simply use mail() function to send mail. You can also connect to SMTP server via socket but then you need to handle whole protocol communication.

PHP mail() not working

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.

Exchange rejecting php mail from same domain

I have an IIS server running PHP on an Apache Module. I am running a domain on it, and this domain has a seperate setup for email which uses an exchange server. When I try to send email from the website using php mail() the exchange server rejects it. I.e. the header from line is sender#this-domain.com and it is sending to receiver#this-domain.com, both are email addresses set up in the exchange, even though the sender has no direct relationship with exchange.
The emails are not getting through. We tried using a Yahoo adress in the from line but nothing. Has anyone ever come across a problem like this.
You have to either configure the exchange server to accept relay requests based on the origin ip or some transparent authorization mechanism (don't know much about IIS and Exchange and integrated windows authentication, but the good people over at http://serverfault.com do. ). Or use some mailing library that can handle smpt authentication like e.g. http://swiftmailer.org
I once ran into a problem like this which involved the Exchange server not wanting to accept anonymous connections or that it would only accept mail from certain SMTP servers. Have you checked the configuration on your Exchange server to eliminate those possibilities?

PHP PEAR Mail: Relay access denied

I can send emails to myself and other people on my mail server using PEAR Mail. But when I try to send to another server, I get an error:
Relay access denied.
I've checked the SMTP configs and they're exactly the same as in my email client.
What could it be?
Relay access denied.
A "relay" is a mail server that acts as an open gateway, allowing anyone to connect to it and send mail through it ... to anyone. If the target isn't local, a relay will make a best effort to pass it on.
Obviously this is a tremendously bad idea.
Chances are that the mail server you are using is either locked down to local delivery only, or it wants you to authenticate first to prove that you are permitted to send mail through it.
You will need to contact your sysadmin to ask him or her about the error, and exactly what you need to do in order to send mail through it.
Is your email client authenticating to your SMTP server? Most servers will allow authorized/authenticated users to relay mail through them. That way you can be (say) a salesman in a hotel room somewhere and still send mail to a 3rd party via your corporate mail server.
Check that your PHP mail call is using the proper SMTP credentials (which means username/password, not just the server address). Since your email client can relay, but your script can't, most likely the script isn't authenticating.

Categories