treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Mmail not coming to gmail from contact us form?

  • I downloaded this form http://css-tricks.com/examples/NiceSimpleContactForm/. my client use free gmail account and he want to get all mail in his gmail account through contact us form. I tested this but mail not coming to gmail.

    This is the code of form php

    <?php

    $EmailFrom = \"chriscoyier@gmail.com\";
    $EmailTo = \"CHANGE-THIS@YOUR-DOMAIN.com\";
    $Subject = \"Nice & Simple Contact Form by CSS-Tricks\";
    $Name = Trim(stripslashes($_POST['Name']));
    $Tel = Trim(stripslashes($_POST['Tel']));
    $Email = Trim(stripslashes($_POST['Email']));
    $Message = Trim(stripslashes($_POST['Message']));

    // validation
    $validationOK=true;
    if (!$validationOK) {
    print \"<meta http-equiv=\\"refresh\\" content=\\"0;URL=error.htm\\">\";
    exit;
    }

    // prepare email body text
    $Body = \"\";
    $Body .= \"Name: \";
    $Body .= $Name;
    $Body .= \"\n\";
    $Body .= \"Tel: \";
    $Body .= $Tel;
    $Body .= \"\n\";
    $Body .= \"Email: \";
    $Body .= $Email;
    $Body .= \"\n\";
    $Body .= \"Message: \";
    $Body .= $Message;
    $Body .= \"\n\";

    // send email
    $success = mail($EmailTo, $Subject, $Body, \"From: <$EmailFrom>\");

    // redirect to success page
    if ($success){
    print \"<meta http-equiv=\\"refresh\\" content=\\"0;URL=contactthanks.php\\">\";
    }
    else{
    print \"<meta http-equiv=\\"refresh\\" content=\\"0;URL=error.htm\\">\";
    }
    ?>


    I just changed this

    $EmailFrom = \"chriscoyier@gmail.com\";
    $EmailTo = \"CHANGE-THIS@YOUR-DOMAIN.com\";

    to this

    $EmailFrom = \"myname@gmail.com\";
    $EmailTo = \"myname@gmail.com\";


    What is the problem, what is the purpose of $EmailFrom? user will fill their own email in form.
  • The point of $Emailfrom is so that you can set a certain static email to have it LOOK like its coming from a certain person all the time. So if you set it to yourself, or to say "contact@mysite.com", it doesn't go to spam and you can even have it separated into a particular folder everytime. However, if you set the From to the $Email parameter instead, it will grab the input the user provides and will tell you its coming from that. Its up to you there.
  • try this


    <?php
    if(isset($_POST[\"submit\"])){
    $to=\"mail@callus24x7.com\";
    $name=trim(addslashes($_POST[\"name\"]));
    $cno=trim(addslashes($_POST[\"cno\"]));
    $email=trim(addslashes($_POST[\"email\"]));
    $add=trim(addslashes($_POST[\"add\"]));

    $message=\"Name : \".$name.\"\n\n\";
    $message=$message.\"Contact No :\n \".$cno.\"\n\n\";
    $message=$message.\"Email :\n \".$email.\"\n\n\";
    $message=$message.\"Address :\n \".$add.\"\n\n\";

    mail($to,\"Email\",$message,\"From:$email\");
    mail(\"krushna.c@gmail.com\",\"Enquiry\",$message,\"From:$email\");
    ?>
    <script type=\"text/javascript\">
    alert(\"Your message is sent Successfully .....\");
    document.location=\"index.php\";
    </script>
    <?php
    }
    ?>







    <form id=\"form1\" name=\"form1\" method=\"post\" >
    <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">
    <tr>
    <td width=\"24%\">&nbsp;</td>
    <td width=\"18%\">&nbsp;</td>
    <td width=\"44%\">&nbsp;</td>
    <td width=\"14%\">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td valign=\"bottom\"><span class=\"style1\">Name :</span></td>
    <td valign=\"bottom\"><span class=\"style1\">Address : </span></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input name=\"name\" type=\"text\" id=\"name\" /></td>
    <td rowspan=\"5\" valign=\"top\"><textarea name=\"add\" cols=\"40\" rows=\"8\" id=\"add\"></textarea></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td valign=\"bottom\"><span class=\"style1\">Contact No : </span></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td height=\"28\">&nbsp;</td>
    <td valign=\"top\"><input name=\"cno\" type=\"text\" id=\"cno\" /></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td valign=\"bottom\"><span class=\"style1\">Email : </span></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td valign=\"top\"><input name=\"email\" type=\"text\" id=\"email\" /></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td valign=\"top\">&nbsp;</td>
    <td valign=\"top\">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td colspan=\"2\" align=\"left\" valign=\"top\"><input name=\"submit\" type=\"submit\" id=\"submit\" value=\"Submit\" style=\"border:0px\" />
    <input type=\"reset\" name=\"Submit2\" value=\"Reset\" style=\"border:0px\" /></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td valign=\"top\">&nbsp;</td>
    <td valign=\"top\">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </form>