0

I am trying to build a form where its contents will be emailed. I have been following this post here as I have never dealt with forms before nor PHP. I have the front-end of the form working, but am unsure if the back-end PHP portion will work.

My question is how would I test and deploy my PHP code onto my client's web host? I am assuming that to test I would have to install Apache and Mercury (via XAMPP) so that I would have a local mail server? How about when I deploy my code to my client's web host. Would I have to do any special configurations, or can I upload the files like I normally would?

Javascript (copied from here)

var data = "This is my email";

$.ajax({
    type: "POST",
    url: "email.php",
    data: data,
    dataType: "text"
});

PHP (also copied from here)

$to = "myself@hotmail.com";
$subject = "This is my email";
$message = $_REQUEST["data"];
$send = mail($to, $subject, $message);

if (!$send) {    
    die();  
}
Community
  • 1
  • 1
Jeff
  • 3
  • 1
  • It's hard to say without knowing exactly what hardware setup you're using. however, most webhosts have everything configured "out of the box" and a simple `mail()` shouldn't give you much trouble – Paul Dessert Jul 02 '12 at 23:32
  • I am pretty sure my client is using GoDaddy as he mentioned his webhosts advertised with a lot of attractive ladies. I am assuming GoDaddy will be appropriately pre-configured for me? – Jeff Jul 02 '12 at 23:36
  • I also think one of the existing pages on his web server has a form, and I assume that the contents from that form is sent to his email. As there will be multiple forms on his web host, will this complicate my situation? – Jeff Jul 02 '12 at 23:38
  • :) Funny! It should be. You should be just fine. – Paul Dessert Jul 02 '12 at 23:38
  • "As there will be multiple forms on his web host," No, as long as you code everyhting correctly, you won't have an issue – Paul Dessert Jul 02 '12 at 23:39

2 Answers2

0

You'd have to have the email.php file with the PHP code surrounded by <?php /*code here*/ ?> in the appropriate directory on the web server. The web server will have to have PHP support. You could try making a file <?php print "PHP works." ?> on your webserver and going to it in your browser.

Conner
  • 30,144
  • 8
  • 52
  • 73
  • I don't have access to the web server yet, but I am 100% sure it supports PHP as I see an existing form on his website already. In addition, I also think one of the existing pages on his web server has a form, and I assume that the contents from that form is sent to his email. As there will be multiple forms on his web host, will this complicate my situation? – Jeff Jul 02 '12 at 23:39
  • Not if you're just submitting to your single, standalone script. You can use something like [XAMP](http://www.apachefriends.org/en/xampp.html) to make an easy web server on your personal computer so you can test your code out without using the production server. – Conner Jul 02 '12 at 23:42
0

I would not recommend Apache and Mercury (via XAMPP). My isp blocked email from my home machine so this option would only work to deliver to local host. It took more time to set up that it was worth. A better bet would be to put your code on the server and try it out live.

I can already tell you it's not going to work.

Try this for your ajax code. Post parameters have to be key-value pairs.

var data = "This is my email";

$.ajax({
    type: "POST",
    url: "email.php",
    data: {
        data : data
    },
    dataType: "text"
});
jarchuleta
  • 1,231
  • 8
  • 10