SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Message part of contact form not working.

    I am sure I have something wrong here, but dang if I can find it. The contact form works fine except the message does not come through. Perhaps someone could put another set of eyes on it and clue me in? Thanks.
    This is the HTML:

    Code HTML4Strict:
    <form id="ContactForm" method="post" action="contact.php">
                            		<div>
    									<div  class="wrapper">
    										<strong>Name:</strong>
    										<div class="bg"><input type="text" class="input" name="Name:" ></div>
    									</div>
    									<div  class="wrapper">
    										<strong>Email:</strong>
    										<div class="bg"><input type="text" class="input" name="Email:" >	</div>							
    									</div>
    									<div  class="textarea_box">
    										<strong>Message:</strong>
    										<div class="bg"><textarea name="textarea" cols="1" rows="1" ></textarea>		</div>						
    									</div>
    									<a href="#" class="button" onClick="document.getElementById('ContactForm').submit()"><span><span>Send</span></span></a>
    									<a href="#" class="button" onClick="document.getElementById('ContactForm').reset()"><span><span>Clear</span></span></a>
    								</div>
    							</form>


    And this is the PHP behind it:

    Code PHP:
    <?php
    $field_name = $_POST['Name:'];
    $field_email = $_POST['Email:'];
    $field_message = $_POST['textarea'];
     
    $mail_to = 'xxxxxxx@xxx.xxx';
    $subject = 'Message from a site visitor '.$field_name;
     
    $body_message = 'From: '.$field_name."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Message: '.$field_textarea;
     
    $headers = 'From: '.$field_email."\r\n";
    $headers .= 'Reply-To: '.$field_email."\r\n";
     
    $mail_status = mail($mail_to, $subject, $body_message, $headers);
     
    if ($mail_status) { ?>
    	<script language="javascript" type="text/javascript">
    		alert('Thank you for the message. We will contact you shortly.');
    		window.location = 'contact_page.html';
    	</script>
    <?php
    }
    else { ?>
    	<script language="javascript" type="text/javascript">
    		alert('Message failed. Please, send an email to [email]firstvirginiaservices@yahoo.com[/email]');
    		window.location = 'contact_page.html';
    	</script>
    <?php
    }
    ?>

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    ok, you define
    PHP Code:
    $field_message $_POST['textarea']; 

    but then call
    PHP Code:
    $body_message .= 'Message: '.$field_textarea

    in the actual body_message variable......
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ View Post
    ok, you define
    PHP Code:
    $field_message $_POST['textarea']; 

    but then call
    PHP Code:
    $body_message .= 'Message: '.$field_textarea

    in the actual body_message variable......
    Okay, I totally appreciate the response. However I am not as smart as you think I am. I changed the fields that were in red in your response to match one another, but it still doesn't work. Can you hold my hand just a bit more please?

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    spikeZ was trying to point out $field_message and $field_textarea are two different variables (not the red text; which is just the color of strings).

    In short, you either need to change $field_message to $field_textarea or you need to change $field_textarea to be $field_message

  5. #5
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah Hah! Thank you so much!!!!! Cookies for you

  6. #6
    Non-Member
    Join Date
    Sep 2012
    Location
    Sweden
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Some ready-made code here:

    <?
    if(isset($HTTP_POST_VARS['act']) && $HTTP_POST_VARS['act']=="process") {
    //
    if($HTTP_POST_VARS['name']!="" && $HTTP_POST_VARS['email']!="" && $HTTP_POST_VARS['comments']!="") {
    //
    $headers = "Return-path: <".stripslashes($HTTP_POST_VARS['email']).">\n";
    $headers .= "Reply-to: <".stripslashes($HTTP_POST_VARS['email']).">\n";
    $headers .= "Content-Type: text/html; charset=windows-1252\n";
    $headers .= "Content-Transfer-Encoding: 7bit\n";
    $headers .= "From: ".stripslashes($HTTP_POST_VARS['name'])."<".stripslashes($HTTP_POST_VARS['email']).">"."\n";
    $headers .= "X-Priority: 3\n";
    $headers .= "X-Mailer: EasyCM X-Mailer Version 2.01\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "\n\n";
    $message = wordwrap('<p>Visitor contacted!</p><p>Name: '.stripslashes($HTTP_POST_VARS['name']).'<br>Email: '.stripslashes($HTTP_POST_VARS['email']).'</p><p>Questions &amp; Comments: '.stripslashes($HTTP_POST_VARS['comments']).'</p>', 70);

    $mailto = 'your@emailaddress.com';

    mail($mailto, 'From Site Visitor', $message, $headers);

    echo '<script>alert("Your message has been sent!");</script>';

    unset($HTTP_POST_VARS);
    } else {
    echo '<script>alert("You have not entered all required information.");</script>';
    }

    }
    ?>


    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><?
    //echo '<b>'.TEXT_CONTACT_FORM.'</b>';
    ?>
    <FORM name="form1" action="" method="post">
    <TABLE class=main style="WIDTH: 100%; BORDER-COLLAPSE: collapse" cellSpacing=2 cellPadding=2>
    <TBODY>
    <TR>
    <TD>
    <INPUT name=name class="formfield" style=" width: 382px; color: #000000; background: #F1F7F8;" value="<?=$HTTP_POST_VARS['name'];?>" ></TD>
    <TD width="100%" style="WIDTH: 100%"> - Full Name</TD>
    </TR>
    <TR>
    <TD><INPUT name=email class="formfield" style=" width: 382px; color: #000;background: #F1F7F8;" value="<?=$HTTP_POST_VARS['email'];?>" ></TD>
    <TD style="WIDTH: 100%"> - Email</TD>
    </TR>
    <TR>
    <TD>
    <TEXTAREA name="comments" class="formfield" style=" width: 380px; height: 110px;color: #000;background: #F1F7F8;"><?=$HTTP_POST_VARS['comments'];?></TEXTAREA></TD>
    <TD style="WIDTH: 100%"> - Comments</TD>
    </TR>

    <TR>
    <TD>
    <input type=submit class="formfield" style="background: #F1F7F8; width: 140px; HEIGHT: 25px; color: #000000; font-family: Verdana, Sylfaen, Arial" value="Send Now!" name=submit>
    </TD>
    <TD style="WIDTH: 100%">
    <input name="act" type="hidden" id="act" value="process">
    </TD>
    </TR>
    </TBODY>
    </TABLE>
    </FORM></td>
    </tr>
    </table>

  7. #7
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by euro-space View Post
    Some ready-made code here:
    There are many many issues with that code, first and foremost HTTP_POST_VARS was deprecated in version 5.3
    http://php.net/manual/en/migration53.deprecated.php

    Your code lacks any type of validation, opening up a few different error scenarios.

    Lastly, the poster had a workable and usable product, he didn't need a new way of performing the task, just needed help finding an error in his code.


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
  •