Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Contact Form for site with no ASP ( linux hosting )

  • 19-06-2009 9:22am
    #1
    Registered Users, Registered Users 2 Posts: 242 ✭✭


    Hi all,

    Do any have code for a simple contact form ( name , email , number , ennquiry ) that will send the form direct to an email address laid out properly.

    I have a good code for this already but it is asp based and the website i am doing at the moment is on a linux hosting plan with no asp and to move to a windows plan is messy.

    Any help greatly appriciated.

    Thanks.

    SD


Comments

  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    Google for PHP contact form - I'd imagine your UNIX host will support that.

    This is the first result from google:
    http://www.phpeasystep.com/phptu/8.html


  • Registered Users, Registered Users 2 Posts: 242 ✭✭SD1990


    Hi Eoin , thanks for that.

    The mail sends from the form now but it just sends a black email ?

    The PHP obviously isnt connect to the form ?
    Can anyone see the problem?

    Not the best with PHP.

    Code on contact.php
    <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>
    

    code on send_contact.php
    <?php
    // Contact subject
    $subject ="$subject"; 
    // Details
    $message="$detail"; 
    // Mail of sender
    $mail_from="$customer_mail"; 
    // From 
    $header="from: $name <$mail_from>"; 
    // Enter your email address
    $to [EMAIL="='myemail@myemail.com'"]='myemail@myemail.com'[/EMAIL]; 
    $send_contact=mail($to,$subject,$message,$header);
    // Check, if message sent to your email 
    // display message "We've recived your information"
    if($send_contact){
    echo "We've received your contact information";
    }
    else {
    echo "ERROR";
    }
    ?>
    


  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    I don't know much PHP either, but should the dollar be in the field names like that?

    <td><input name="$name" type="text" id="name" size="50"></td>


  • Registered Users, Registered Users 2 Posts: 242 ✭✭SD1990


    i put them in trying to fix it. It doesnt work with or without them..


  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    try

    $mail_from= $_POST;


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 242 ✭✭SD1990


    That did it. Thanks Eoin. Much Appriciated. :)

    Any idea how to get it to say Name: , Email : Query : in the actual email?

    Im imagining its done in sent_contact.php next to the one you want like

    "Detials="$_POST; ??


  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    Yep, it would be something like that - but I don't really know PHP.

    Google for PHP string concatenation and you should find out how.


  • Registered Users, Registered Users 2 Posts: 242 ✭✭SD1990


    any know how to make it "from" form@mysite.com ??

    now its saying Nobody"nobody.mail.indigo.com" for from.

    also the email address wont come up in the body of the email just the details and the name.


  • Registered Users, Registered Users 2 Posts: 3,141 ✭✭✭ocallagh


    You need to add an additional paramatr to the mail function to set a from address, and it's not as easy as the to address. You have to use the additional headers parameter

    Try changing $header variable to one of the following
    $header = 'From: [EMAIL="webmaster@example.com'"]webmaster@example.com'[/EMAIL] . "\r\n" .
        'Reply-To: [EMAIL="webmaster@example.com'"]webmaster@example.com'[/EMAIL] . "\r\n" ;
    

    $header = [EMAIL="'-fwebmaster@example.com';"]'-fwebmaster@example.com';[/EMAIL]
    

    To add string together use the dot character or just throw the $ variable into the string
    eg
     
    $name = $_POST["name"];
    $email = $_POST["email"];
    $detail = $_POST["detail"];
    $subject = $_POST["subject"];
     
    $message = "Name: $name, Email: $email, Detail: $detail";
     
    $send_contact=mail($to,$subject,$message,$header);
     
    


Advertisement