JoeLongstreet Posted April 3, 2009 Share Posted April 3, 2009 I am definitely not a PHP developer but I need a little help on a basic contact form I'm working on. Works ok so far, but I need to clean it up a little bit. This single line is the main concern, where $message is the body section of the email sent: $message = htmlspecialchars($_POST['name'] . '\n' . 'email' . '\n' . 'guests'); I thought the '\n' would make a new line in the sent email, but it didn't. Also, the guests variable is a select/option thing in the contact form and it is not sending it's value in the $message. Any help is much appreciated. Thanks, Joe HTML Form: <form id="rsvp" action="mail.php" method="post"> <div id="buttons"> <input class="button" id="rsvpButton" type="image" src="images/rsvpButton.png" /> </div><!--buttons--> <div id="inputs"> <label id="nameLabel" for="name">name</label> <input id="name" type="text" name="name" class="input" /> <label id="emailLabel" for="email">email</label> <input id="email" type="text" name="email" class="input" /> <label id="guestsLabel" for="guests">attending (including you)</label> <select id="guests" name="guests"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6+</option> </select> </div><!--inputs--> </form> PHP: <?php error_reporting(E_NOTICE); function valid_email($str) { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } if($_POST['name']!='' && $_POST['email']!='' && valid_email($_POST['email'])==TRUE) { $to = "[email protected]"; $headers = 'From: '.$_POST['email'].''. "\r\n" . 'Reply-To: '.$_POST['email'].'' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = "Addition to Wedding Guest List"; $message = htmlspecialchars($_POST['name'] . '\n' . 'email' . '\n' . 'guests'); if(mail($to, $subject, $message, $headers)) { echo 1; //SUCCESS } else { echo 2; //FAILURE - server failure } } else { echo 3; //FAILURE - not valid email } ?> Link to comment https://forums.phpfreaks.com/topic/152471-designer-needs-help-with-php/ Share on other sites More sharing options...
Ayon Posted April 3, 2009 Share Posted April 3, 2009 not sure, but you could try this: $message = htmlspecialchars($_POST['name'] . "\n" . $_POST['email'] . "\n" . $_POST['guests']); Link to comment https://forums.phpfreaks.com/topic/152471-designer-needs-help-with-php/#findComment-800783 Share on other sites More sharing options...
yami007 Posted April 3, 2009 Share Posted April 3, 2009 yeah u should use double quotes ^^ Link to comment https://forums.phpfreaks.com/topic/152471-designer-needs-help-with-php/#findComment-800785 Share on other sites More sharing options...
Maq Posted April 3, 2009 Share Posted April 3, 2009 yeah u should use double quotes ^^ Actually double or single it doesn't matter when using a dot to concatenate to the string. If you're putting the variable straight in the string (not breaking out of it) then you must use double quotes or the variables will not interpolate. As far as your linebreaks if your email is HTML you might have to use instead of \n. Anyway, this should include the number of guests and the email in your message. Good luck. $to = "[email protected]"; $headers = "From: " . $_POST['email'] . "\r\n" . "Reply-To: " .$_POST['email'] . "\r\n" . "X-Mailer: PHP/" . phpversion(); $subject = "Addition to Wedding Guest List"; $message = htmlspecialchars($_POST['name'] . "\n email" . $_POST['email'] . "\n guests" . $_POST['guests']); if(mail($to, $subject, $message, $headers)) { Link to comment https://forums.phpfreaks.com/topic/152471-designer-needs-help-with-php/#findComment-800789 Share on other sites More sharing options...
JoeLongstreet Posted May 5, 2009 Author Share Posted May 5, 2009 Thanks for all the help. Got it working good. Even put some jquery in it. Thanks, Joe Link to comment https://forums.phpfreaks.com/topic/152471-designer-needs-help-with-php/#findComment-826805 Share on other sites More sharing options...
Maq Posted May 5, 2009 Share Posted May 5, 2009 Thanks for all the help. Got it working good. Even put some jquery in it. Thanks, Joe Great, you mind sharing the final solution for others with the same problem. You should also mark this solved. Link to comment https://forums.phpfreaks.com/topic/152471-designer-needs-help-with-php/#findComment-826815 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.