I've just made some fixes to a web site that uses the Form2Mail PHP script. This worked on my home machine, a while back, but I have suddenly been pressured to release today, and it is already 3pm here.
I am an ASP.NET developer and know very little PHP, so if I have to improvise, writing my own version of the script is not a very feasible option. What other options to I have that can allow me to, out of the box, cause an HTML form's submit event to result in an email being sent to a configured email address?
sending mails in php is very simple http://php.net/manual/en/function.mail.php
you would just put a form that submits to something like mail.php, stick some mail code in there and you are done
Related
I currently have a static website that I am trying to send an email form from. I am using a simple HTML form with fields such as name, email, message, etc. The PHP form is also very straight forward. I don't think there are any problems with the code. In fact, the code is basically exactly like any online tutorial you'd find (http://www.freecontactform.com/email_form.php). I think the problem has to do with the config on the server. I have a Digital Ocean server with Nginx. At first, when I tried to submit the email form I was getting a 405 error. Now that I handle 405 errors in the config file, I am getting the PHP form as a download when I hit the submit button. What do I need to install on the server or include in the config file to make this PHP email form work?
Edit/Update: I have installed Postfix on my web server and am able to successfully send emails from command line using Postfix to different emails outside the server (for instance, I can send from my root user to my personal email addresses on Gmail, etc.). I now have another problem...
This still doesn't help me on the front-end. When I try to click the submit button on the web page form it is still just downloading the PHP file. I think I am missing something in the php.ini folder and maybe some other things as well. Even though I have mail set up on the server, the PHP action button has no idea that it's set up or something along those lines.
You need to install a Mail Transport Agent (MTA) like postfix or exim4. I think you can configure nginx to rely emails to another smtp server.
Another way, would be installing swiftmailer and connect it with an email sending service as sendgrid, mandrill, sparkpost, etc.
Edit:
I personally recomend a sending service as they have white-listed IP for their sending services plus you save memory in your VPS server (as an MTA daemon is not required to run there).
I'm using sparkpost for a few projects and is working perfectly. They have a pretty high limit for a free account.
With any service you choose, ensure to enable DKIM and SPF to avoid been detected as spam.
I´m using Drupal (PHP) and sometimes I use it to send email to some of my registered users (ie. using a contact form located inside their profile). This is very common in every CMS, PHP forum, etc.
The thing is that Drupal usually prints out a successful message when the email was sent, and not always the email is actually sent.
On the other hand, my hosting uses VHM panel with VPS servers.
From their control panel I can check all mail that goes from my server to the outside. In VHM it´s called "Mail Delivery Reports". That´s accurate enough, and I think most VPS control panel probably have some similar utility.
My question is: When Drupal tells me that the email has been sent, and I go to the Mail Delivery report on my hosting control panel, and it says that it has not been sent. Is that a PHP flaw?
Is there a way to get accurate reports within PHP?
Please excuse my grammar. It has been kinda difficult for me to actually get myself clear on what I mean in english.
UPDATE:
I´m not asking if the user reads the email, not even if it later on gets bounced, just to know if PHP has some accurate way to report if the email was sent.
I know there are some services offering that, but I´m just asking about PHP capabilities (and if that´s actually possible).
PHP responsibility is to give it to your specified transport method. (sendmail, smtp etc.) and tell you if the transport accepted it or not.
If you use sendmail (or postfix) what php tells you is that it has been queued for sending and nothing else. PHP doesn't know if it will be sent or not. unless you parse the queues and try to go from there.
No. It is impossible for PHP to track sent emails. That is not, never has been, and never will be, PHP's job.
PHP simply generates the email (e.g. builds the html) and then hands it over to a mail transfer agent. e.g. your local sendmail.
In a real-world equivalent, PHP is you walking an envelope down to the street corner and dropping it into the mailbox. If the letter disappears down the chute, PHP will report success. After that, actual DELIVERY of the mail is entirely out of PHP's hands.
Maybe the mailbox gets flattened by a drunk driver, maybe the pickup truck gets into a firey crash, maybe the postal sorting facility gets hit by a meteor, etc...
None of that is PHP's problem, and undetectable by PHP anyways. It walked down the street, it saw the letter disappear down the slots. Mission accomplished.
At best you could set the "return service requested" mail headers, which 99.99% of people will probably ignore or disallow, or embed a web-bug inside the email and hope that the recipient's mail client will actually load the bug.
On my directory website I have a "send email" functionality. This lets a user submit an enquiry to a company. A copy of this enquiry is also sent to my inbox.
A few months ago I noticed that I had stopped receiving the email copy to my inbox. So I investigated this and it turned out that my web host was no longer allowing sending external emails using the PHP mail function.
When I questioned this I was told that I would need to start using a third party mail plugin, and I was recommended to use PEAR.
So I converted my PHP script to use PEAR and managed to get it working on my site. All was good until until one day I thought it would be a good idead to switch to PHP 5.3 on my web host. A few days later I noticed that I had again stopped receiving the email copy to my inbox.
So again I investigated this and found that it was broken. I was told that I would need to revert back to PHP 5.2 for this to work. So basically that's what I had to do to make it work again.
My question is, how can I know when the mail functionality is broken as soon as it breaks? During the time it takes for me to realise it's broken, several enquiries could be being sent from the site which aren't actually going anywhere.
And secondly should I stick with PEAR or are there any better alternatives out there?
There are a number of alternatives to PEAR::Mail. However first I have to address the question of whether your goal is to pay your hosting company so that they arbitrarily break your site and subsequently, your business? I'm not sure why anyone would pay to be on a habitrail wheel of fail, and pay for that.
With that said this package http://swiftmailer.org/ has become very popular and is bundled as part of the symfony2 framework, which is an excellent endorsement of its functionality and support for the latest/greatest features in PHP.
Prior to that, http://phpmailer.worxware.com/ was a very popular package.
As for detecting whether your mail is working, the only way to do that is to have an automated test job that sends you an email every day, or at whatever periodicity you want. If you don't get that email, you know that there is an issue that requires investigation.
I have a question about PHP.
I want to create a really simple page with only one function.
a text box, and a button to send it to my e-mail address.
**/ I don't really even get the concept of a .php file, or how to implement it to a html file (or do I just create a php file?)
I've been surfing on the web for a way, but quite can't get it.
If you can give me some advice on it, I'd really appreciate it.
I wrote the program, but won't send it to the address("itoyanlifelog#gmail.com").
I'm running it on MAMP, local server.
1) use php mail() function: http://fr2.php.net/manual/en/function.mail.php
2) if you are on a local machine be sure that you can send emails from local. Take a look here: http://wiki.uniformserver.com/index.php/PHP_mail_function
I know it is possible to send html enabled emails. Is it also possible to send PHP enabled emails?
For this to count:
php code has to be sent as plain text
php code has to be executed on some server X only after recipient opens the email
Server X is not the recipient's machine
If this is possible, what are the consequential security issues that this brings up?
You are basically trying to force the remote email client to display a remote HTML page (generated by PHP). No clients will do that, because it's a big security risk.
You could use AJAX, but all modern email clients will completely block any Javascript in the emails by default.
You can however request remote images. You could generate them on the fly (handle the jpg extension by PHP and generate the image on the fly), but that's very likely to kill your emails as spam by any spam filter. Most email clients will block remote images by default, but will usually show a button to unblock them (this does not happen for javascript scripts).
I think your best bet is sending HTML with an iFrame or you can try an Ajax call to get the HTML you want to inject (using javascript). I don't think you can just send PHP code embedded in the HTML.
Check example #4 http://php.net/manual/en/function.mail.php
This cannot be done in the way I think you are thinking. You cannot send PHP code and expect it to be interpreted by the email client.
However, you can link to an image, on your server, in the HTML email. And this image could be a PHP script which runs on your server. But most email clients do not display images by default for this very reason.