Greetings!
I am not new to web applications, but I just started learning PHP syntax this morning.
I had to help a friend today with a PHP survey and I'm trying to make sure I follow "best practices".
I created the form and the script that mails it out. The Mail works as intended, sends to the appropriate places, redirects, etc, but there is a TON of whitespace in the message body.
I have tried removing \n, tried str_replace( "\n", "\r\n", $message), and a few other things trying to get it to work, but no matter what I do, there is WAY too much white space on the "other side".
If I output the contents of $message in a string using a PRE tag, I am able to reproduce it, but without that PRE formatting, it's just one long string.
My other question is: where can I find information about the best way to prevent form spamming in PHP? I found several instances of avoiding injections, but I'm not sure this applies as I'm not having them enter an e-mail address as it's just a survey.
Any pointers would be greatly appreciated!
TIA!
Sunshine
<?php
$RnB_Soul=($_POST['RnB_Soul'])?"RnB Soul":"";
$Blues=($_POST['Blues'])?"Blues":"";
$Rock=($_POST['Rock'])?"Rock":"";
$Reggae=($_POST['Reggae'])?"Reggae":"";
$Heavy_Metal=($_POST['Heavy_Metal'])?"Heavy Metal":"";
$Country=($_POST['Country'])?"Country":"";
$Classical=($_POST['Classical'])?"Classical":"";
$Jazz=($_POST['Jazz'])?"Jazz":"";
$Gospel=($_POST['Gospel'])?"Gospel":"";
$musictypes="\n$RnB_Soul\n$Blues\n$Rock\n$Reggae\n$Heavy_Metal\n$Country\n$Classical\n$Jazz\n$Gospel\n$Contemporary_Christian\n$Praise_and_Worship";
$Contemporary_Christian=($_POST['Contemporary_Christian'])?"Contemporary Christian":"";
$Praise_and_Worship=($_POST['Praise_and_Worship'])?"Praise and Worship":"";
$Contemporary_Gospel=($_POST['Contemporary_Gospel'])?"Contemporary Gospel":"";
$Christian_Rap_=($_POST['Christian_Rap_'])?"Christian Rap":"";
$Contemporary_Praise_and_Worship=($_POST['Contemporary_Praise_and_Worship'])?"Contemporary Praise and Worship":"";
$Spirituals=($_POST['Spirituals'])?"Spirituals":"";
$Christian_Jazz=($_POST['Christian_Jazz'])?"Christian Jazz":"";
$Traditional_Hymns=($_POST['Traditional_Hymns'])?"Traditional Hymns":"";
$musicstyles="\n$Contemporary_Christian\n$Praise_and_Worship\n$Contemporary_Praise_and_Worship\n$Contemporary_Gospel\n$Christian_Rap_\n$Christian_Jazz\n$Spirituals\n$Traditional_Hymns";
$Favorite_Artists = $_POST["Favorite_Artists"];
$TimePreference = $_POST["TimePreference"];
$TimePreferenceOther = $_POST["TimePreferenceOther"];
$message = "Favorite Music Types:
$musictypes
What Are Your Preferences of Musical Styles In Worship?
$musicstyles
Who Are Your Favorite Musical Artists?
$Favorite_Artists
What time would you prefer to go to church?\n
$TimePreference\n
Other:\n
$TimePreferenceOther\n
";
$to = "myAddress@MyDomain.com";
$subject = "Web site Survey results";
$headers = "From: website@theirdomain.com\r\n" .
"CC: anotheraddress@yetanotherdomain.com\r\n" .
"X-Mailer: php";
if (mail($to, $subject, $message, $headers)) {
header( "Location: http://www.domaintoredirect.org/thanks.html" );
} else {
echo("<p>Message delivery failed...</p>");
}
?>
(Changed CODE tags to PHP tags -- NogDog)