Jump to content

Recommended Posts

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@email.net";
	$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

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@email.net";
      $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)) {

  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.