Form field not processing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Aliroy
Forum Newbie
Posts: 2
Joined: Tue Nov 08, 2011 10:30 pm

Form field not processing

Post by Aliroy »

Hello,
My form on my page sends the email to me but the message does not send.
There are 3 fields: Name, Email, Message
When I get an email after the user submits the form, Name and Email shows in the from field, but
The body of the email does not display the Message.

Any suggestions on how I can fix this.

The Form

Code: Select all

    <form id="contact_form" method="post" action="<?php echo $target_url; ?>">
        <p>
        	<input id="your_name" name="your_name" type="text" title="<?php _e( 'Name', THEMEDOMAIN ); ?>*" style="width:94%"/>
        </p>
        <p style="margin-top:20px">
        	<input id="email" name="email" type="text" title="<?php _e( 'Email', THEMEDOMAIN ); ?>*" style="width:94%"/>
        </p>
        <p style="margin-top:20px">
        	<textarea id="message" name="message" style="width:94%" title="<?php _e( 'Message', THEMEDOMAIN ); ?>*"></textarea>
        </p>
        <p style="margin-top:30px"><br/>
        	<input type="submit" value="<?php _e( 'Send Message', THEMEDOMAIN ); ?>"/>
        </p>
    </form>

The form processing script, which is on the same page

Code: Select all

/*
	|--------------------------------------------------------------------------
	| Mailer module
	|--------------------------------------------------------------------------
	|
	| These module are used when sending email from contact form
	|
	*/
	
	//Get your email address
	$contact_email = get_option('pp_contact_email');
	
	//Enter your email address, email from contact form will send to this addresss. Please enter inside quotes ('myemail@email.com')
	define('DEST_EMAIL', $contact_email);
	
	//Change email subject to something more meaningful
	define('SUBJECT_EMAIL', __( 'Email from contact form', THEMEDOMAIN ));
	
	//Thankyou message when message sent
	define('THANKYOU_MESSAGE', __( 'Thank you! We will get back to you as soon as possible', THEMEDOMAIN ));
	
	//Error message when message can't send
	define('ERROR_MESSAGE', __( 'Oops! something went wrong, please try to submit later.', THEMEDOMAIN ));
	
	
	/*
	|
	| Begin sending mail
	|
	*/
	
	$from_name = $_GET['your_name'];
	$from_email = $_GET['email'];
	
	$mime_boundary_1 = md5(time());
    $mime_boundary_2 = "1_".$mime_boundary_1;
    $mail_sent = false;
 
    # Common Headers
    $headers = "";
    $headers .= 'From: '.$from_name.'<'.$from_email.'>'.PHP_EOL;
    $headers .= 'Reply-To: '.$from_name.'<'.$from_email.'>'.PHP_EOL;
    $headers .= 'Return-Path: '.$from_name.'<'.$from_email.'>'.PHP_EOL;        // these two to set reply address
    $headers .= "Message-ID: <".$now."webmaster@".$_SERVER['SERVER_NAME'].">";
    $headers .= "X-Mailer: PHP v".phpversion().PHP_EOL;                  // These two to help avoid spam-filters

    # Boundry for marking the split & Multitype Headers
    $headers .= 'MIME-Version: 1.0'.PHP_EOL;
    $headers .= "Content-Type: multipart/mixed;".PHP_EOL;
    $headers .= "   boundary=\"".$mime_boundary_1."\"".PHP_EOL;
	
	$message = 'Name: '.$from_name.PHP_EOL;
	$message.= 'Email: '.$from_email.PHP_EOL.PHP_EOL;
	$message.= 'Message: '.PHP_EOL.$_GET['message'];
	    
	
	if(!empty($from_name) && !empty($from_email) && !empty($message))
	{
		mail(DEST_EMAIL, SUBJECT_EMAIL, $message, $headers);
	
		echo THANKYOU_MESSAGE;
		
		exit;
	}
	else
	{
		echo ERROR_MESSAGE;
		
		exit;
	}
	
	/*
	|
	| End sending mail
	|
	*/
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Form field not processing

Post by social_experiment »

What happens if you change the $_GET values in your script to $_POST? Your form submits using $_POST so you can access all the form data via $_POST['fieldname']
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Aliroy
Forum Newbie
Posts: 2
Joined: Tue Nov 08, 2011 10:30 pm

Re: Form field not processing

Post by Aliroy »

I tried that but it still did not work. The body of the email was still blank.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Form field not processing

Post by Celauran »

What is $target_url? If the form and the processing code are on the same page, you should just leave action blank or use $_SERVER['PHP_SELF'].
Post Reply