SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP sending mail using a form

    Hi guys,

    I'm setting up a simple form which sends a mail with the data entered. I was wondering if I needed to configure anything on the server to enable this? My code is as follows, I've tested it and I have not recieved the email yet:
    Code:
    <?php
    $to = "myemailaddress@gmail.com";
    $subject = "Contact Us";
    $email = $_REQUEST['email'] ;
    $message = $_REQUEST['message'] ;
    $headers = "From: $email";
    $sent = mail($to, $subject, $message, $headers) ;
    if($sent)
    {header( "Location: http://www.irongatesandrailings.co.uk/confirm.html" );} 
    else
    {header( "Location: http://www.irongatesandrailings.co.uk/error.html" );}
    ?> 
    
    <form method="post" action="contact.php" id="contactform">
    				<div>
    					<label for="fullname">Name:</label>
    					<input type=text" name="fullname" id="fullname" class="txt"/>
    				</div>
    				<div>
    					<label for="email">Email Address:</label>
    					<input type="text" name="email" id="email" class="txt"/>
    				</div>
    				<div>
    					<label for="message">Message:</label>
    					<textarea name="message" id="message" cols="30" rows="5" class="txt"></textarea>
    				</div>
    				<div >
    					<input type="submit" name=btnSubmit" id="btnSubmit" value="Send" class="btn"/>
    				</div>
    			</form>
    Thanks!

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The email has arrived, better late that never eh? The only doubt I have is now, is how do I include the sender's name in the email too?

    Thanks!

  3. #3
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You want to put the sender's email address in the email body?

    PHP Code:
    <?php

    $message 
    $_REQUEST['message'] . "\r\n";
    $message .= "Sender's email address is: " $email "\r\n";
    my mobile portal
    ghiris.ro

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to put the sender's name in the email body. Is it the same code as you have posted but swapping $email for $name?

    thanks for your help!

  5. #5
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes
    my mobile portal
    ghiris.ro


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
  •