1

I am new to php and trying to send email to my gmail through form. On clicking submit, i dont see any error on the page but I dont get an email. My from id and to mail id exists and from email id is on the server(making sure not to spam).

<?php
    if(isset($_POST['submit'])){
        $to = "existingmygamilid@gmail.com";
        $subject = "Pickup Request";
        $mailContent = $_POST['name'].$_POST['adress'].$_POST['mobile'].$_POST['email'].$_POST['message'];
        $message = "
        <html>
        <head>
        <title> Pickup Request</title>
        </head>
        <body>
        <p>Hey!... You got a pickup request.</p>
        ";

        // Always set content-type when sending HTML email
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

        // More headers
        $headers .= 'From: <existingemail@testdomain.com>' . "\r\n";

        mail($to,$subject,$message,$headers);
    }
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" class="alt" method="POST">
    <div class="row uniform 50%">
        <div class="6u 12u$(xsmall)">
            <input name="name" placeholder="Name" type="text" />
        </div>
        <div class="6u$ 12u$(xsmall)">
            <input name="address" placeholder="Address" type="text" />
        </div>
        <div class="6u 12u$(xsmall)">
            <input name="mobile" placeholder="Mobile or Landline" type="text" />
        </div>
        <div class="6u$ 12u$(xsmall)">
            <input name="email" placeholder="Email" type="email" />
        </div>                            
        <div class="12u$">
            <textarea name="message" rows="6"></textarea>
        </div>
    </div>
    <ul class="actions">
        <li><input type="submit" value="Send message" /></li>
    </ul>
</form>
Community
  • 1
  • 1
Kurkula
  • 6,386
  • 27
  • 127
  • 202
  • There's a million reasons why your mail doesn't arrive to your incoming folder. But basically because your mail server provider rejected something coming from "testdomain.com" and coming from a non SPF IP. – Amarnasan Sep 22 '15 at 07:00
  • Amarnasan, testdomain.com is my server name and as I mentioned n the question, I made sure that emailids are not spam and domain name is existing domain. I tried test code with out form and it works fine. – Kurkula Sep 22 '15 at 07:03

4 Answers4

1

Try this:

<ul class="actions">
    <li><input type="submit" value="Send message" name="submit" /></li>
</ul>

Give 'name' for the submit button. Other wise your isset($_POST['submit'] won't work

arunrc
  • 628
  • 2
  • 14
  • 26
1

Try this

<?php
    if(isset($_POST['submit'])){
        $to = "existingmygamilid@gmail.com";
        $subject = "Pickup Request";
        $mailContent = $_POST['name'].$_POST['adress'].$_POST['mobile'].$_POST['email'].$_POST['message'];
        $message = "
                    <html>
                    <head>
                    <title> Pickup Request</title>
                    </head>
                    <body>
                    <p>Hey!... You got a pickup request.</p><br><p>";
        $message .= $mailContent;
        $message .= "</p></body></html>";
        // Always set content-type when sending HTML email
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

        // More headers
        $headers .= 'From: <existingemail@testdomain.com>' . "\r\n";

        mail($to,$subject,$message,$headers);
    }
?>

<form action="" class="alt" method="post">
    <div class="row uniform 50%">
        <div class="6u 12u$(xsmall)">
            <input name="name" placeholder="Name" type="text" />
        </div>
        <div class="6u$ 12u$(xsmall)">
            <input name="address" placeholder="Address" type="text" />
        </div>
        <div class="6u 12u$(xsmall)">
            <input name="mobile" placeholder="Mobile or Landline" type="text" />
        </div>
        <div class="6u$ 12u$(xsmall)">
            <input name="email" placeholder="Email" type="email" />
        </div>
        <div class="12u$">
            <textarea name="message" rows="6"></textarea>
        </div>
    </div>
    <ul class="actions">
        <li><input type="submit" name="submit" value="Send message" /></li>
    </ul>
</form>

Errors are

  1. Missing attribute(name="submit") in submit
  2. No usage of $mailContent
  3. No closing tags in mail body( Missing </body> and <html>)
  4. Wrong declaration of action="<?php echo $_SERVER['PHP_SELF']; ?>"
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
1

This condition fail in your code

if(isset($_POST['submit']))

You need to give name attribute to your submit button and it will work <input type="submit" name="submit" value="Send message" />

Ankur
  • 496
  • 1
  • 6
  • 11
1

Change this line

<input type="submit"  name="submit" value="Send message"/>
Tal
  • 1,091
  • 12
  • 25