1

I've developed an iOS app and rails backend server. While I took some HTML classes back in university, it's been a long while since I've touched any.

I purchased a 'template' website to be my application landing page. I've tweaked it to be what I want, but I'm having 1 issue with the Contact/Form Submission page. When I press send, I do not receive an email at the intended email address. I'm not sure if this is an issue with the code (I'm guessing not, I would think this highly rated template would have had something like this correct), or if I need to set up something with my domain that I currently haven't done as I wouldn't know about it.

Here's the relevant code...

index.html

<form action="javascript:;" method="post">
    ...
    <input type="submit" class="button white" value="Send &#x2192;" />
</form>

send_email.php

<?php

    // Replace this with your own email address
    $to="example@gmail.com";

    // Extract form contents
    $name = $_POST['name'];
    $email = $_POST['email'];
    $website = $_POST['website'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];

    // Validate email address
    function valid_email($str) {
        return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
    }

    // Return errors if present
    $errors = "";

    if($name =='') { $errors .= "name,"; }
    if(valid_email($email)==FALSE) { $errors .= "email,"; }
    if($message =='') { $errors .= "message,"; }

    // Send email
    if($errors =='') {

        $headers =  'From: FluidApp <no-reply@fluidapp.com>'. "\r\n" .
                    'Reply-To: '.$email.'' . "\r\n" .
                    'X-Mailer: PHP/' . phpversion();
        $email_subject = "Website Contact Form: $email";
        $message="Name: $name \n\nEmail: $email \n\nWebsite: $website \n\nSubject: $subject \n\nMessage:\n\n $message";

        mail($to, $email_subject, $message, $headers);
        echo "true";

    } else {
        echo $errors;
    }

?>

However, nothing is being sent to my email "example@gmail.com".

What might I be missing here?

chris P
  • 6,359
  • 11
  • 40
  • 84
  • You say your app is on ruby on rails but your send email code is in php. – doru Jul 05 '15 at 19:30
  • @doru My app is for iOS, aI wrote it's backend server in rails. However, I purchased a "landing page" website template (this one to be exact http://themeforest.net/item/fluidapp-responsive-mobile-app-website-template/2251839), which is written in HTML, CSS, PHP. I'm just tweaking it to show my images, etc. I didn't want to write a site from scratch. My apps server and this landing page are 2 different things. Probably shouldn't have even mentioned my app or backend. – chris P Jul 05 '15 at 19:32
  • For debugging see [PHP mail form doesn't complete sending e-mail](http://stackoverflow.com/q/24644436) – mario Jul 05 '15 at 19:36
  • Are you sure there's an SMTP server? – vpzomtrrfrt Jul 05 '15 at 19:44
  • @vpzomtrrfrt No, I'm not sure. I bought the cheapest option off of namecheap for a domain and hosting. I'm not too familiar with the dashboard right now or where to check, but I'm looking into it. Any ideas? – chris P Jul 05 '15 at 19:54

2 Answers2

3

Maybe replace

<form action="javascript:;" method="post">

with

<form action="send_email.php" method="post">

That should do it, assuming the ... in your HTML snippet contains the right variables for the form submission- name, email, website, subject, message, etc.

EDIT: OP figured it out.

Community
  • 1
  • 1
Blue Ice
  • 7,888
  • 6
  • 32
  • 52
  • Yeah, they contain the right variables. After replacing that with "send_email.php", upon pressing "Send" I'm taken to myexamplewebsite.com/send_email.php and the page just reads "true" from the echo statement in php. However, no email sent after 5 mins of waiting. – chris P Jul 05 '15 at 19:29
  • @chrisP Hmm. Maybe take a peek at this line: `$to="example@gmail.com";` ? – Blue Ice Jul 05 '15 at 19:36
  • It seems to be good. I've quintuple verified the address I have in there is my email address. – chris P Jul 05 '15 at 19:55
  • Thanks. Do I need to configure anything on my website domain management, or hosting management? I bought the cheapest hosting and domain I could off of namecheap yesterday. Is there some configuration I might be missing? – chris P Jul 05 '15 at 20:06
  • @chrisP I tested your code and it seems to be running fine. However, I ran it on localhost, which means that I won't be able to get emails either. I think the problem lies somewhere in your server setup- can you tell me if you are hosting the website locally or remotely? Let's continue our discussion in a chat room [here](http://chat.stackoverflow.com/rooms/82427/chat-for-blue-ice-and-chris-p)- it'll be easier instead of using comments. Thanks. – Blue Ice Jul 05 '15 at 20:32
  • Maybe try a library designed for this purpose such as PHPMailer instead of using PHP's mail function. It makes my life easier. – tomysshadow Jul 05 '15 at 20:53
  • Got it. Needed to add the from email. Whoops. – chris P Jul 05 '15 at 22:00
  • @chrisP, I'm adding a link to your comment in my answer. If you wish, you can mark my answer with the checkmark if you feel like it helped. – Blue Ice Jul 05 '15 at 22:06
-1

Place the <form action="send_email.php" method="post">

and remove <form action="javascript:;" method="post">

it will work perfect your send_email.php is good

place all 2 files in same folder

blex
  • 24,941
  • 5
  • 39
  • 72
Ashok Bhamla
  • 7
  • 1
  • 8