Results 1 to 8 of 8

Thread: Contact form

  1. #1
    Join Date
    Oct 2010
    Posts
    19
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Contact form

    Hallo,

    I got here a contact form.
    Although its working for 50%
    He atleast sends the mail to mine e-mail and i receive it.
    Besides that i can also see the subject of the mail.
    Either though i cant see the rest of the mail is total empty.

    I have got this contact form from: http://phpeasystep.com/phptu/8.html
    I just try to make a simple contact form.
    I got 2 files:
    - contact.php
    - send_contact.php

    The files codes are here:
    Contact.php
    HTML Code:
    <table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
    <tr>
    <td><strong>Contact Form </strong></td>
    </tr>
    </table>
    
    <table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
    <tr>
    <td><form name="form1" method="post" action="send_contact.php">
    <table width="100%" border="0" cellspacing="1" cellpadding="3">
    <tr>
    <td width="16%">Subject</td>
    <td width="2%">:</td>
    <td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
    </tr>
    <tr>
    <td>Detail</td>
    <td>:</td>
    <td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
    </tr>
    <tr>
    <td>Name</td>
    <td>:</td>
    <td><input name="name" type="text" id="name" size="50"></td>
    </tr>
    <tr>
    <td>Email</td>
    <td>:</td>
    <td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>
    send_contact.php
    PHP Code:
    <?php
    $subject 
    ="$subject"
    $message="$detail";

    $mail_from="$customer_mail"
    $header="from: $name <$mail_from>";

    $to ='mymail@provider.com';

    $send_contact=mail($to,$subject,$message,$header);

    if(
    $send_contact){
    echo 
    "We've received your contact information";
    }
    else {
    echo 
    "ERROR";
    }
    ?>
    If somebody could help me out i would be really thankful
    Thanks in advance.
    Greetz,

    Jan24

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    That is a bad tutorial. You need to set the variables to be able to send them. Try this code below.

    PHP Code:
    <?php
    $subject 
    $_POST['subject'];
    $message$_POST['detail'];

    $mail_from$_POST['customer_mail'];
    $name $_POST['$name'];
    $header="From: $name <$mail_from>";

    $to ='mymail@provider.com';

    if (
    mail($to,$subject,$message,$header)) {
    echo 
    "We've received your contact information";
    } else {
    echo 
    "ERROR";
    }
    ?>
    Corrections to my coding/thoughts welcome.

  3. The Following User Says Thank You to bluewalrus For This Useful Post:

    jan24 (10-11-2010)

  4. #3
    Join Date
    Nov 2008
    Posts
    58
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Default

    I have got this contact form from...
    The code is wrong. It assumes register globals is on.

    The link has a free contact form code that you can just 'just plug in'

    PHP Contact form tutorial

  5. The Following User Says Thank You to prasanthmj For This Useful Post:

    jan24 (10-11-2010)

  6. #4
    Join Date
    Oct 2010
    Posts
    19
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    Thanks to both of u for your reply
    Altough to prasanthmj i rather stick with this code.
    Either though it needs some changes but i can build from it and the link you give me is to much script for what i need. Still though thanks

    To bluewalrus Thanks!
    Now more things are working but still not all. The Subject he is sending just like before. But now he also sends the message. But when i try to add more fields to it like 3 fields he doesnt sends at all anymore and get a error.

    I changed it likes this i added a line like this at the contact.php:
    HTML Code:
    <tr>
    <td>Last name</td>
    <td>:</td>
    <td><input name="last_name" type="text" id="last_name" size="50"></td>
    </tr>
    This code is working fine so far.

    And added at the send_contact.php this:
    PHP Code:
    $last_name $_POST['last_name']; 
    And added at the line the $last_name so he will send it also:
    PHP Code:
    if (mail($to,$subject,$last_name,$message,$header)) { 
    But then mostly i get a error but still sending email, when i add another field i get a error and dont get a email at all.
    Its bit odd to me. To me it looks like he cant send more then 5 variables and i want to send more.

    I hope u can help me out with this.
    Thanks in advance

  7. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    The mail php function only takes 4 values you'll need to put the last name into one of the other variables you already have. Do you want it in the subject, the body or the from tag?

    http://php.net/manual/en/function.mail.php

    This example shows how you'd do it with the from field


    PHP Code:
    $header="From: $name $last_name <$mail_from>";
    if (
    mail($to,$subject,$message,$header)) { 
    Another example using the "." to concatenation all the values.

    PHP Code:
    $header"From " $name " " $last_name " <$mail_from>"
    Corrections to my coding/thoughts welcome.

  8. The Following User Says Thank You to bluewalrus For This Useful Post:

    jan24 (10-11-2010)

  9. #6
    Join Date
    Oct 2010
    Posts
    19
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    I got it now all working!! Really great thanks a lot!
    Although i am using at the moment a hotmail account for testing.
    When i test the form i get the email with all the data i entered.

    Although it goes into my spam folder with the message: That this email isnt trusted by their SmartScreen-filters and will be deleted after 10 days.

    Of course i dont want to get this email into my spam folder how i fix this?

    BTW in the form i entered the email bart@hotmail.com

  10. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    The spam problem could be because the server sending the email and the domain of the from don't match up. I don't usually use a from address. You can put that in the body of the email and it should be fine or even in the subject.
    Corrections to my coding/thoughts welcome.

  11. The Following User Says Thank You to bluewalrus For This Useful Post:

    jan24 (10-11-2010)

  12. #8
    Join Date
    Oct 2010
    Posts
    19
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    Alright i think i will do that then
    I think mostly all is solved all the rest i can fix out by myself
    Thanks a lot for your help and time
    This topic is solved

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
  •