Results 1 to 6 of 6

Thread: contact form contents is not delivering to my email

  1. #1
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question contact form contents is not delivering to my email

    When i fill my webiste contact form n submit the form the email is not delivering to my inbox nor spam
    My hosting person says that the code must be in 5.4 version so can u please help me out with this


    contact_msg.php(file name)

    PHP Code:
    <?
        $to 
    "sunil@blitzhunt.com";
        
    $from "From: ".$_POST['email'];

        
    $subject "Enquiry";
        
    $message "Dear Admin,\r\n";
        
    $message .= "Please find below order form submitted by a visitor at the website: \r\n";
        
    $message .= "----------------------------------------\r\n";
        
    $message .= "Visitor Name: ".$_POST['cname']."\r\n";
        
    $message .= "Visitor Email: ".$_POST['email']."\r\n";
        
    $message .= "Visitor Phone: ".$_POST['phone']."\r\n";
        
    $message .= "Visitor Address: \r\n";
        
    $message .= $_POST['address']."\r\n";
        
    $message .= $_POST['city']."\r\n";
        
    $message .= $_POST['state']."\r\n";
        
    $message .= "----------------------------------------\r\n";
        
    $message .= "System Alert!";
        
        
    ini_set("sendmail_from""sunil@blitzhunt.com");
        
    mail($to,$subject,$message,$from);
    ?>
    Mod's note:

    Please do not post the same thread multiple times. Sometimes, legitimate posts get caught in our spam filter. Moderators will review and approve these as quickly as possible; usually within a few hours.

    Please be patient. Posting again only slows this process and makes more work for us.
    Last edited by traq; 03-24-2014 at 04:02 PM. Reason: mod's note; please use BBCode tags

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    The code you posted is fully compatible with PHP version 5.4.

    That being said, there are some major shortcomings with it.

    First off, it is vulnerable to header injection - a spammer could use your form to send email to a huge mailing list. You must never trust user input. Always check user-submitted data to validate that it is the data you expected, and sanitize it as necessary (depending on how it will be used).

    In this case, you expect $_POST["email"] to be a single email address. You can validate this with filter_var:
    PHP Code:
    $email filter_var$_POST["email"],FILTER_VALIDATE_EMAIL )?
        
    $_POST["email"]:
        
    null;

    if( ! 
    $email ){
        
    /* the submitted email address was not valid.
            provide an error message, etc.,
            and _do not_ try to send the email. */
        
    exit;
    }

    // if the email address was valid, you can use it:
    $from "From: $email\r\n"
    Secondly, before trying to process the form submission, you need to make sure the form was actually submitted. You don't know if $_POST["email"], $_POST["address"], etc., even exist. Before trying to use external variables, you need to check that they are set —e.g., using isset:
    PHP Code:
    if( ! isset( $_POST["email"] ) ){
        
    /* the form field "email" was not submitted.
            maybe the user reached this page by using the [back] button?
            maybe it's a hacking attempt?
            _do not_ try to send the email.  */

    Third, this line:
    PHP Code:
    ini_set("sendmail_from""sunil@blitzhunt.com"); 
    …does nothing productive and could (probably) be removed.

    Also, note that the short open tags ( <? ) are not supported on all servers; it is much better to use the full open tags ( <?php ).

    And finally, if your email is being sent, it might be being dropped as spam if the "From" address does not match the domain it was sent from. If you want to put the visitor's email address in the "From" header, then you need to also include a "Sender" header that provides an email address from your domain.

    You might also be interested in learning more about programming basics and how to troubleshoot code.
    Last edited by traq; 03-25-2014 at 07:12 PM.

  3. #3
    Join Date
    Jul 2008
    Posts
    136
    Thanks
    13
    Thanked 1 Time in 1 Post

    Default

    As always traq never fails to explain in depth. He will steer you in the right direction. You'll always want to check if the form is submitted from your form page (unless you do this all in the same form) to prevent direct attacks like he mentioned. Ex. someone goes to your processing page directly and injects data to send spam, then your ISP flags you for sending spam.

    The code has changed through the years, but this was one I used back in the day and it detects spam bots etc. http://jemsmailform.com/

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    One more thing I forgot to mention: the mail function returns TRUE or FALSE depending on its success:
    PHP Code:
    //  . . .

    $success mail$to,$subject,$message,$from );

    if( 
    $success ){
        
    /*  mail() completed successfully.
            while this doesn't _necessarily_ mean that the email was actually sent or recieved
            (it only means that the mail server accepted the message),
            it is a fairly good indicator.  */
    }
    else{
        
    /*  mail fail!
            definitely didn't work.  */

    Last edited by traq; 03-25-2014 at 07:24 PM.

  5. #5
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i am totally confused can u please get me the full code .

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by savni2000 View Post
    i am totally confused
    Perhaps I wasn't clear—while the code you posted could be improved, there is, strictly speaking, nothing wrong with it.

    It's okay if you don't understand it all at once. Just take it one step at a time.

    Try outputting the result of you call to mail, to see if the function is succeeding or not:
    PHP Code:
    $success mail$to,$subject,$message,$from );

    var_dump$success );  // this will print either "bool( TRUE )" or "bool( FALSE )" 
    If the result is FALSE, you can start looking for other error messages or possible causes.

    If the result is TRUE, then the email is probably being sent but discarded as spam along the way. The first thing you should do to address that is add a "Sender" header to the email, as I described in my post above.

    Quote Originally Posted by savni2000 View Post
    can u please get me the full code .
    If you are looking for someone to do the work for you, you can post in the Paid Work Requests forum.

    Otherwise, I am happy to help you solve this yourself, but it will require effort on your part. Do your best to understand what is going on -do some research on your own, try to follow directions to troubleshoot your code, experiment with possible solutions- and if you need more help with specific parts, let me know and I'll be happy to explain further.

Similar Threads

  1. Replies: 5
    Last Post: 12-04-2013, 03:35 PM
  2. Replies: 5
    Last Post: 08-17-2011, 04:15 PM
  3. Making Email Contact Form Secure
    By Lemon in forum JavaScript
    Replies: 14
    Last Post: 04-09-2010, 12:58 AM
  4. Contact email form
    By Wizzap in forum Looking for such a script or service
    Replies: 1
    Last Post: 03-23-2008, 03:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •