Results 1 to 10 of 10

Thread: Contact Us Form php issue

  1. #1
    Join Date
    Jul 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Contact Us Form php issue

    Hello
    I have a website with an online subscription form in PHP.

    Current status:

    Step1/- A visitor fills in his name and email address.
    Step 2/- Next, I get visitor name and email address inside my INBOX.
    Step 3/- Next, I send an email to confirm his email address.
    (Like...Just reply me back to confirm your email address etc...)


    Current PHP form
    ==========================
    [[[ Page with PHP Form Code ]]]

    <form name="form" id="form" method="post" action="thankyou.php">
    <table width="100%" border="0" cellspacing="2" cellpadding="2">
    <tr>
    <td><span class="style66">Name*</span></td>
    <td><input name="name" type="text" id="name" /></td>
    </tr>
    <tr>
    <td><span class="style66">E-mail*</span></td>
    <td><input name="email" type="text" id="email" /></td>
    </tr>
    <tr>
    <td colspan="2"><div align="center">
    <p> </p>
    <p>
    <input id="submit" type="image" src="images.png"value="submit"

    name="submit" rntsubmit="true">
    </p>
    </div></td>
    </tr>
    </table>
    </form>
    ===========================

    ===========================
    [[[ Confirmation Page Code ]]]

    <?php
    $name = $_REQUEST['name'] ;
    $email = $_REQUEST['email'] ;
    $body = "A user $name send data \n".
    "Name: $name\n".
    "Email: $email \n".
    mail( "myemail@mydomainname.com", "User Data via Web Form", $body );
    ?>
    ===================================================

    Question:
    I want to automate the step 2 and step 3.
    Like,.. I get visitor data inside my inbox but at the same time website visitor also gets an automatic email message from my side.

    Best wishes,
    Dave
    ======================

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

    Default

    Please use the forum's bbcode tags and indent your code to make it more readable:

    for php code............[php] <?php /* code goes here */ ?> [/php]
    for html...............[html] <!-- markup goes here -->.....[/html]
    for js/css/other.......[code] code goes here................[/code]


    What you want will require a way to keep track of contact submissions, the email addresses that you've sent to, and the email address that have been confirmed (i.e., the replies you recieve). In other words, you'll need a database.

    The process (logic) would go something like this:

    # User submits form:

    PHP validates the form submission

    IF not valid PHP rejects it (show an error page, or something)

    ELSE, PHP checks the database to see if the email address already exists

    IF not, PHP:

    -- saves the email address to the database
    -- creates a unique confirmation code/link
    -- sends the link to the user's email address
    -- send the admin (you) a notification

    # THEN, we wait for the user to click on the link in the email:

    PHP checks the database to see if the confirmation code is valid

    IF it is, PHP updates the database to show that the email was confirmed, and send the admin (you) a notification

    ELSE, PHP rejects the confirmation (show an error page, or something)

  3. #3
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    function SendUserConfirmationEmail(&$formvars)
    {
    $mailer = new PHPMailer();
    $mailer->CharSet = 'utf-8';
    $mailer->AddAddress($formvars['email'],$formvars['name']);
    $mailer->Subject = "Your registration with ".$this->sitename;
    $mailer->From = $this->GetFromAddress();
    $confirmcode = urlencode($this->MakeConfirmationMd5($formvars['email']));
    $confirm_url = $this->GetAbsoluteURLFolder().'/confirmreg.php?code='.$confirmcode;
    $mailer->Body ="Hello ".$formvars['name']."\r\n\r\n".
    "Thanks for your registration with ".$this->sitename."\r\n".
    "Please click the link below to confirm your registration.\r\n".
    "$confirm_url\r\n".
    "\r\n".
    "Regards,\r\n".
    "Webmaster\r\n".
    $this->sitename;
    if(!$mailer->Send())
    {
    $this->HandleError("Failed sending registration confirmation email.");
    return false;
    }
    return true;
    }

    this will work

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

    Default

    are you talking about PHPmailer? A lot of the methods you're using don't seem to be on their methods list.

    Aside from that, your example only addresses the "sending mail" part (and out of curiosity, why are you passing $formvars by reference?) - he needs to track the emails and follow up on confirmation replies as well.

  5. #5
    Join Date
    Jul 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Current status:

    Step 1/- A visitor fills in his email address.
    Step 2/- Next, I get visitor email address inside my INBOX.
    Step 3/- Next, I send him a following email message, manually.
    =============Start Message==========
    Subject: Verification required - Newsletter Subscription
    Body:
    Welcome to MY DOMAIN NAME.com
    You, or someone using your email address, has applied
    at http://mydomainname.com to receive our newsletter

    "Just reply us back to confirm your email address"

    If this is an error, ignore this email and you will be removed from our
    mailing list.

    Regards,
    http://My Domain Name - Team
    ============= End Message==========



    Current PHP form consist of two pages

    ===================================
    [[[ Page with PHP Form Code | Page NO.1 Formpage.php ]]]

    <html><body>
    <form name="myform" method="post" action="SEND.php"><br> <br />
    <input name="email" type="text" id="email" />
    <br />
    <input type="submit" name="Submit" value="Submit" />
    </form>
    </body></html>
    ==================================================
    [[[ Confirmation Page Code | Page NO.2 SEND.php ]]]

    <?php
    $email = $_REQUEST['email'] ;
    mail( "myemail@mydomain.com", "Newsletter Request", "From: $email" );
    ?>
    ===================================================

    Question:
    I want to automate the step 2 and step 3.
    Like,.. I get visitor Email address inside my inbox but at the same time website visitor also gets an automatic email verification message from my side. I just want that visitor to reply me back to confirm his e-mail address.

    What code I write to send an auto-email to $email?

    Best wishes,
    Dave
    ======================

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    PHP has no way of checking to see if new mail is in an inbox- so your idea of automating this process (seems to be) impossible. I think the order in which you're thinking about this is wrong. It is possible, however, if you send a test e-mail to the person who's trying to set it up. Try it this way:

    1) Visitor fills in e-mail address
    2) A test e-mail is sent to HIS/HER address with a link in it. This link will go to a page that will change some DB value in accordance with that e-mail address to verify it
    3) Once the link is clicked, the e-mail is verified, then you can add his/her e-mail to the subscribe list

    This is how most sign-up forms work for anything. If you need specifics you can message me.
    - Mike

  7. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Did you read my post (post #2 above)?

    I outlined a possible solution for automating the process. Do you currently have a database for your site? Do you have any experience writing PHP that interacts with a database?

    If you have any questions about my suggestion, please, ask! I'll be happy to help you figure it out.

    If you are looking for someone to just write the code for you, you should post in the paid help forum.

    Edit:

    @mburt

    Actually, PHP can check email boxes, but its complicated and not really necessary for this sort of task.
    The approach you outlined is preferable (very close to what I described as well).

    Edit:

    @mburt
    Sorry: only the "edit" portion of this post was directed at your reply.
    My "did you read" question was directed at the OP.

    Last edited by traq; 04-07-2012 at 04:32 AM.

  8. #8
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    @traq Yeah I read through your post, but I wanted to re-iterate the facts and simplify the process. (I do realize that essentially we are suggesting the same thing).
    - Mike

  9. #9
    Join Date
    Jul 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow

    Hi

    I did a little search about headers and my problem has solved.
    My PHP script is working fine. Thanks to good forum and quick members.

    Now, there is another issue. It is about security!
    I have heard that spammers use php code injection, malicious script and do spamming.

    How can I secure this simple two pages php form?

    Best wishes,
    Dave
    =============

    Current PHP form consist of two pages
    =================================================
    [[[ Page with PHP Form Code | Page NO.1 Formpage.php ]]]

    <html><body>
    <form name="myform" method="post" action="SEND.php"><br> <br />
    <input name="email" type="text" id="email" />
    <br />
    <input type="submit" name="Submit" value="Submit" />
    </form>
    </body></html>
    =================================================
    [[[ Confirmation Page Code | Page NO.2 SEND.php ]]]

    <?php
    $email = $_REQUEST['email'] ;
    mail( "myemail@MyDomainName.com", "Newsletter Request", "From: $email" );
    ?>

    <?php
    $subject="Verification required - Newsletter Subscription";
    $body ="
    Welcome to MY DOMAIN NAME.com
    You, or someone using your email address, has applied
    at http://mydomainname.com to receive our newsletter

    Just reply us back to confirm your email address

    If this is an error, ignore this email and you will be removed from our
    mailing list.
    Regards,
    http://My Domain Name - Team
    ";
    $headers = 'From: myemail@MyDomainName.com' . "\r\n" .
    'Reply-To: myemail@MyDomainName.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    mail( $email, $subject, $body, $headers );
    ?>

    =================================================

  10. #10
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Simple just use:

    Code:
    $_POST["email"]
    not

    Code:
    $_REQUEST["email"]
    That way there is no chance of the get variable getting injected into the code. Other than that it looks pretty secure.
    - Mike

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
  •