HTML Form variables / PHP variables help


#1

I’m working on online membership application form for my amateur club’s website. The goal is collect the data in HTML then pass it to PHP. In PHP will take the variables format them in an email and send that data to the membership committee for there review. The form contains text, radio, and select elements.

Some of the text variables are passing through but non or the radio or select elements.

Here is code for the php portion:

<?php

	$to = 'portamex@garlic.com';

	$subject = 'SFARC Member application Test';

	$from = 'membership@w6ek.com';

 

// To send HTML mail, the Content-type header must be set

	$headers  = 'MIME-Version: 1.0' . "\r\n";

	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 

// Create email headers

	 $headers .= 'From: '.$from."\r\n".

    'Reply-To: '.$from."\r\n" .

    'X-Mailer: PHP/' . phpversion();



// Declare PHP variables from html input

 

 	 $date = $_POST['date'];

    $first_name = $_POST['first_name'];

    $last_name = $_POST['last_name'];

    $nick_name = $_POST['nick_name'];

    $address = $_POST['home_address'];

    $city_town = $_POST['city_town'];

    $zip_code = $_POST['zip_code'];

    $email = $_POST['email'];

    $home_phone = $_POST['home_phone'];

    $cel_phone = $_POST['cel_phone'];

    $call_sign = $_POST['call_sign'];

    $arrl_member = $_POST['arrl_member'];

    $membership_type = $_POST['membership_type'];

    $membership_length = $_POST['membership_length'];

    $payment_method = $_POST['payment_method'];

    $membership_dues = $_POST['membership_dues'];

    

function clean_string($string) {

	$bad = array("content-type","bcc:","to:","cc:","href");

	return str_replace($bad,"",$string);

}

 

 // Generate application in a message

	$message = "Date: " $date

    "First Name: "$first_name

    "Last Name: "$last_name

    "Nick Name: "$nick_name

    "Address: "$address

    "City/Town: "$city_town

    "Zip Code: "$zip_code    

    "Email: "$email

    "Home Phone: "$home_phone

    "Cel Phone: "$cel_phone

    "Callsign: "$call_sign

    "ARRL Member: "$arrl_member

    "Membership Type: "$membership_type

    "Membership Years: "$membership_length

    "Payment Method: "$payment_method

    "Membership Dues: "$membership_dues"\r\n";



 

// Sending email

if(@mail($to, $subject, $message, $headers )){

    echo 'Your membership application has been successfully submitted.';

} else{

    echo 'Unable to submit your membership application. Please try again.';

}

?>

Also is there any way I can format $message so all the variables do a linefeed and return so they are not all bunched in a single line.

Thanks in advance

HP Garcia

Edited by Benanamen. Added Code Tags


#2

We’d need to see your html form as well.

You need to format this code so we can see it properly.

Don’t suppress errors using @ like in if(@mail()).

Use a mail library like PHPMailer or similar and send your mail through an imap account on a real mail server. Using php’s mail() function, if your server is not perfectly configured as a real mail server there’s a chance all mail you send will be rejected by major mail services like yahoo and g-mail.

line feed can be done as echo $variable . "\n" if the e-mail is plain text or echo $variable . "<br>" if it’s an html e-mail.


#3

ALL of the above will cause a breakage.

If that’s how you want to create your message, then you should be using heredoc, though, I would use a template and replace the content.