Bootstrap PHP Contact Form Not Sending Email? - php

I have done several searches, and I'm not entirely sure what the problem is. Im using bootstrap and a php contact form for a user to input data. This was my reference to building that form: http://rosstanner.co.uk/2012/11/build-simple-contact-form-html-php-bootstrap/
Im able to successfully post in the form, and receive my success or failure alert. However, the email is not actually being sent. My email is in the php file that the form is being redirected to, but is not receiving anything (yes I have checked my spam).
I want to check if there is something server side I am missing (module wise for php). I've just installed LAMP and left it at that. The site works fine, but the form wont post an email.
Thanks!

Without seeing your setup and code, and by looking at the link in your post, I would guess that your PHP.ini file is not setup.
For PHP to be able to send a mail it will need to use an SMTP server. I know a lot of people use Googles (if you have an account) as it's pretty trusted.
There is a great article on setting up your PHP.ini file below:
http://www.quackit.com/php/tutorial/php_mail_configuration.cfm
Another alternative is to install your own mail server. But I wouldn't necessarily recommend this due to problems with SPAM if it is not secured properly.

Related

React Form to send data to PHP script which should then send email

I have been struggling with this one quite a bit... Some background - my React front end is running on a LAMP back end (company's set up not my choice) and I currently have the task of creating a contact form that when submitted - will send the form data to a PHP script which should then trigger an email to be sent to a specific inbox we have set up.
I feel as though I understand the form portion correct as I am most comfortable with HTML/CSS/JS/React, but the LAMP stack set up is really throwing me. I'll try to list specific questions clearly below.
How would one directly target a file on an EC2 instance?
I am currently getting a 500 error (failed to load resource) from the server when attempting to target my PHP file. I have tried an absolute path from the root of the server as well as a path from the root directory of the project. Either way it fails.
I am getting a React warning in console "Form Submission failed because form is not connected", but to my knowledge the form is connected... The action attribute is tied to the PHP file that I would like to send data to.
Currently I have an async await call running when the form is submitted which is supposed to make a fetch/POST call to the file and then things should be handled, but again I am having the issues listed above.
I do not want to share publicly share code because this is a company project, but if someone has experience with this type of set up and has time to help someone trouble shoot please let me know. Sorry for the novel folks and thank you for any help!
Edit - is there any type of work around I could use to avoid even sending this to PHP script and generating an email an alternative way besides emailJS?
If you've created a standard html form then the presumably you have action and method attributes on the form.
You would traditionally:
Set the form action attribute to point at your php script. There should be no reason the php script isn't directly accessible unless it's off document root or you have a .htaccess file that is routing all requests through an intermediary (like an index.php file).
Set the form method attribute to POST.
The PHP script directed to in the action should read from $_POST which is an array that will contain any data sent via POST request to your php script.
You can then use a variety of methods for sending the email. Since you've mentioned EC2 you're obviously in AWS. In this case AWS offer a great email service called Simple Email Service. You can find the SDK and example scripts for sending an email via it here: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-php.html
However, do note that SES requires you to go through a verification process as you will initially be in a sandbox mode that has certain restrictions.

How to open Default Email Application in PHP

Hi Guys I am just this curious, I wonder if PHP can do this stuff:
I have an anchor tag that says "send email to admin".
What I want to do is to open a default email client such ms outlook or lotus and automatically create an empty mail message.
I only want PHP to do it. Is it possible?
If it may, how should I do it?
Use HTML - the browser will handle it.
Click me
PHP only runs on the webserver, it has no access to the programs on a client-computer.
I think you want to use mailto
Fritz Eierschale, fritz.eierschale#example.org
What you describe is possible, though not directly by means pf php:
If I got you right, then you want to offer sending such an email on a web page created by means of php. If so, then all you have to do is use a "mailto" reference. The clients environment will decide what application to open to use that link:
Send email to admin
Note however that this only works, if there is a local email client installed and configured at all on the client side. More and more users use web based email applications instead of a local client, with all the disadvantages. In such case the clients system will popup an error about no suitable application available...

How does a php script on a contact form access the user's email?

This tutorial teaches you how to create a contact form for a website using php script: http://www.boutell.com/newfaq/creating/email.html
But how does this work? How does the script access the user's email account to send an email? How does such a form work without a server? (For example if I put my website on github pages which only handles static pages, how does this php script work?)
there's no way to make the server do something if the server does only throw HTML pages out.
You need some programming language (PHP in your tutorial) to process your code, it has to be installed in the server and accessible to you. It will run your code, decide what to do and do it (by the way to actually send the mail you will need the proper PHP modules available). In this case the script will not use the user's email account to send the mail: it is the server who sends the mail, not the user's client. You will receive an email from your server, so watch out to ask the user for his email, otherwise you will not be able to get it in any way.
If you have no serverside intelligence capacity, just use your user's tools. Which means stuck with the mailto scheme (as the tutorial's first examples show). Then the user's computer will send the email (with the drawbacks the tutorial points out)
It uses the mailto: URI scheme which is opened by your mail client just like skype: scheme is bounded to your Skype client.

Wordpress php sending data to local server

If I have a wordpress website, and a user on the website enters some survey information, is it possible to send the results to a local server inside a company (assuming the website is hosted on some other companies server). From looking around I see people using the JSON formats and GET, PUT etc.. but I havent seen this demonstrated with wordpress. Is there a standard way to do this? I can see it is possible to send via emails, but I was hoping for something more like TCP/IP communications
If it must run through the front-ends WordPress installation, then the easiest way to be a simple HTTP POST request to a server you control. PHP has several different ways you can accomplish this with minimal effort.
The other way you can do this is just to set up a form that will send an AJAX response to your server. Just make sure your receiving server is configured to allow the originating domain.

How do I receive email and process it in a web application

I have set up an email id my PHP web application. Users will send emails to this id.
I want to process these emails in the application. Ho do I go about doing this?
Thanks in advance.
I recently worked on a project that required parsing of email from gmail and updating database with certain values based on the contents of the email. I used the ezcMail (now) Zeta Components library to connect to the mail server and parse the emails.
The strategy I adopted was to filter all interesting incoming mail with a label "unprocessed". Run the PHP script via a crontab every 15 minutes. The script would connect to the mail server and open the IMAP unprocessed folder and parse each email. After inserting the interesting values into the database, the script moves the files to another IMAP folder "Proccessed".
I also found IMAP to be better than POP for this sort of processing.
Recently I wanted to be able to receive emails immediately in something I was making so I did some research (I came looking on this question here too actually) and I ended up finding Google App Engine to be pretty helpful. It has an api you can use to receive and process emails sent to ____#yourapp.appspotmail.com. I know that it doesn't really seem helpful since you probably don't want your app on App Engine and you want to receive emails at yourdomain.tld, but with a little setup you can get what you want.
My basic setup is like this:
User sends email to user_id#mydomain.tld (an email address that doesn't actually exist)
mydomain.tld has a catchall email address that forwards to inbox#GAEapp.appspotmail.com
GAEapp (a tiny app on app engine) receives the email, processes it out, and sends a post request with relevant stuff to mydomain.tld
So basically you can make a little GAE app that works like a go between to grab the emails. Even with the redirect it'll work out ok, the email will be fine.
Also I decided to learn me some django and I made a free app called Emailization that will basically do that for you. You create a recipient like ___#emailization.com and give a URL to POST to. Anything sent to that address gets POSTed to you URL. You can make a catchall on your domain that forwards to that emailization recipient and you'll get email through the catchall too!
or you can see a small GAE app I made that you can setup yourself that does the same thing.
Hope that helps somebody!
Use procmail if it is installed on your system. Put these lines in a .procmailrc file in the home directory of the user who receives the e-mail.
:0
| /path/to/your/script.php
Or you can also use a .forward file containing
"|/path/to/your/script.php"
Procmail has the advantage that it allows you to deal with more complicated filtering if your application ever requires it.
Your script.php file will read the headers and body of the e-mail from stdin.
Check out fMailbox. It does not require any non-standard extensions (such as imap) and has been tested with various servers, attachments, multipart messages, SSL, and more.
I suggest using Zend_Mail component of Zend Framework.
There is a great library: Try this: http://code.google.com/p/php-imap
You need to implement an email client in Php. This is probably going to be a POP client.
This code would query the POP server containing your email, download it, and then you could parse it as needed.
A quick google search of "POP client php" has revealed a vast array of different options. Its hard to tell if there's really "The One True PHP POP Library", otherwise I'd include it here. If you are using a preexisting framework, you may wish to check to see its level of POP support, otherwise check the google results above and take your pick. Or it may just be easiest (and most educational :) ) to roll your own.
There are a number of hosted solutions that will accept email for your domain and then post it a script on your website. Most of these will handle the parsing of the messages for you (separating the attachments, "to" "from" and other addresses, etc).
You just create a script that receives a FORM POST and does whatever you need with it.
Mailgun
CloudMailin
You can also look at Mandrill (by MailChimp), SendGrid, and PostMarkApp.
Hosted solutions as Travis Austin suggested work well.
If you are looking for a self-hosted one, you can have a look at the Mailin module allows you to receive emails, parse them and post them to a webhook of your choice.It also checks the dkim and spf, computes a spamassassin score and determines the message language.
I don't know if it will suit your needs since it is written in node.js, but the more options you have, the better. (Disclaimer: I am the maintainer of Mailin)
There is a great tutorial for this here:
http://www.evolt.org/incoming_mail_and_php
which covers how to have the emails forwarded directly to your script, which your script reads via stdin (fopen, fread, etc.) The tutorial code even does basic parsing of the header/body for you.
If you want to avoid reaching out over POP or IMAP to another server to pull-down the email, you can add a 'hook' into the email receive process on some SMTP server you set up (possibly the same php server). Then just have the destination email handled by this server.
Here is an example with postfix, but similar things are possible with sendmail as well.
http://www.adkap.com/autoresponder.html

Categories