8 Replies - 1074 Views - Last Post: 08 March 2009 - 08:23 PM Rate Topic: -----

#1 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 219
  • View blog
  • Posts: 1,605
  • Joined: 20-January 09

PHP Mail [** SOLVED **]

Posted 07 March 2009 - 11:46 PM

I feel kind of embarrassed asking this question. I made a simple contact form, and am sending the values through fine - but I want to send it through as HTML email, unfortunately though the <br/> tags end up being sent. I know that this is because of the double quotes, but can someone lend a hand on how to put all of this data into the $message variable as HTML, I'm just not sure if I can break the quotes in the mail function or not.

Here is the code:


	$email = $_POST['email'];
		$name = $_POST['name'];
		$reason = $_POST['reason'];
		$comments = $_POST['comments'];
		$sendto = "";
		$subject = "Form feedback from the Whitworth Gallery";
		$message = "From: $name<br>
					Email: $email <br>
					Reason for contact: $reason <br>
					Comments:<br>
					$comments<br>";
					
		$posts = array($email,
					   $name,
					   $reason,
					   $comments);

	/**************************************************************************/
	// PROCESS
	//--------------------------------------------------------------------------
	
		else {
			if (!isset($_POST['submit'])) {
				die ("The form needs to be filled out");
				}
				
			foreach($posts as $key => $value) {
				if($value == "" || $value == NULL) {
					die ("All of the form values must be entered.");
					}
					
			unset($value);
			
			mail("$sendto","$subject","$message");
			header("Location: http://www.whitworthgallery.org/thankyou.php?type=contact");			
			}
		}



Before the else there is an if statement that checks the captcha that is unnecessary for what I need. Also, the mail sends through fine - just not in HTML, so the script works. Thanks for the help guys.

This post has been edited by gregwhitworth: 08 March 2009 - 08:24 PM


Is This A Good Question/Topic? 0
  • +

Replies To: PHP Mail [** SOLVED **]

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5382
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: PHP Mail [** SOLVED **]

Posted 07 March 2009 - 11:47 PM

You need to send your email with html headers

Untested & pulled from the web

<?php
$sendto   = "postmaster@127.0.0.1";
$subject  = "Test HTML email";
$headers  = "Content-Type: text/html; charset=iso-8859-1\n";
$headers .= "From: George <president@whitehouse.gov>\n";
$headers .= "Reply-to: George <president@whitehouse.gov>\n";
$headers .= "\n";
$message  = "<html>";
$message .= "<head>";
# more message
$message .= "</html>";
mail ($sendto, $subject, $message, $headers);
?>



Was This Post Helpful? 0
  • +
  • -

#3 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 219
  • View blog
  • Posts: 1,605
  • Joined: 20-January 09

Re: PHP Mail [** SOLVED **]

Posted 07 March 2009 - 11:56 PM

Quote

.=


Does this concatenate the variable, I've never seen that.
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5382
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: PHP Mail [** SOLVED **]

Posted 07 March 2009 - 11:59 PM

Indeed.

From what I've seen, it's pretty common in this exact application/usage.
Was This Post Helpful? 0
  • +
  • -

#5 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 219
  • View blog
  • Posts: 1,605
  • Joined: 20-January 09

Re: PHP Mail [** SOLVED **]

Posted 08 March 2009 - 12:22 AM

This is what I get in my gmail account:

Quote

<html><head></head><body><h3>From: Greg Whitworth</h3><br><strong>Email:</strong> $email<br><strong>Reason:</strong> Comission<br><strong>Comments:</strong><br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris sem risus, aliquet eget, eleifend eget, faucibus id, purus. Morbi semper aliquet ante. Donec diam. Integer nec libero. Aliquam metus. Aenean malesuada dignissim nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce risus nunc, interdum quis, varius vel, convallis non, enim. Suspendisse posuere. Nulla eu enim. Mauris et leo. Praesent non nisi sollicitudin eros euismod porta.


I got the same result when I used double quotes, the email just isn't sending HTML.

Here is the code:

	$email = $_POST['email'];
		$name = $_POST['name'];
		$reason = $_POST['reason'];
		$comments = $_POST['comments'];
		
		$sendto = "";
		$subject = "Form feedback from the Whitworth Gallery";
		$headers  = "Content-Type: text/html; charset=iso-8859-1\n";
		$headers .= "From: $name\n";
		$headers .= "Reply-to: $email\n";
		$headers .= "\n";
		$message .= '<html>';
		$message .= '<head>';
		$message .= '</head>';
		$message .= '<body>';
		$message .= "<h3>From: $name</h3>";
		$message .= '<br>';
		$message .= '<strong>Email:</strong> $email';
		$message .= '<br>';
		$message .= "<strong>Reason:</strong> $reason";
		$message .= '<br>';
		$message .= '<strong>Comments:</strong>';
		$message .= '<br>';
		$message .= "$comments";
		$message .= '</body>';
		$message .= '</html>';				
	
					
		$posts = array($email,
					   $name,
					   $reason,
					   $comments);

	/**************************************************************************/
	// PROCESS
	//--------------------------------------------------------------------------
		require_once('captcha/recaptchalib.php');
		$privatekey = "6Le0bAUAAAAAAI_cz9eRYKpQEDw88CquozTmgT29 ";
		$resp = recaptcha_check_answer ($privatekey,
										$_SERVER["REMOTE_ADDR"],
										$_POST["recaptcha_challenge_field"],
										$_POST["recaptcha_response_field"]);
		
		else {
			if (!isset($_POST['submit'])) {
				die ("The form needs to be filled out");
				}
				
			foreach($posts as $key => $value) {
				if($value == "" || $value == NULL) {
					die ("All of the form values must be entered.");
					}
			}
					
			unset($value);
			
			mail("$sendto","$subject","$message");
			header("Location: http://www.whitworthgallery.org/thankyou.php?type=contact");
		}

Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5382
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: PHP Mail [** SOLVED **]

Posted 08 March 2009 - 12:26 AM

Probably because you did not include the header variable in your mail function. No sense in building the headers if you have no intention on using them :)
Was This Post Helpful? 0
  • +
  • -

#7 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 219
  • View blog
  • Posts: 1,605
  • Joined: 20-January 09

Re: PHP Mail [** SOLVED **]

Posted 08 March 2009 - 05:11 PM

	$email = $_POST['email'];
		$name = $_POST['name'];
		$reason = $_POST['reason'];
		$comments = $_POST['comments'];
		
		
		
		$sendto = "gkwinspired@gmail.com";
		$subject = "Form feedback from the Whitworth Gallery";
		$headers  = "Content-Type: text/html; charset=iso-8859-1\n";
		$headers .= "From: $name\n";
		$headers .= "Reply-to: $email\n";
		$headers .= "\n";
		$sub_message = "<html>";
		$sub_message .= "<head>";
		$sub_message .= "</head>";
		$sub_message .= "<body>";
		$sub_message .= "<h3>From: ME</h3>";
		$sub_message .= "<br>";
		$sub_message .= "<strong>Email:</strong> $email";
		$sub_message .= "<br>";
		$sub_message .= "<strong>Reason:</strong> $reason";
		$sub_message .= "<br>";
		$sub_message .= "<strong>Comments:</strong>";
		$sub_message .= "<br>";
		$sub_message .= "$comments";
		$sub_message .= "</body>";
		$sub_message .= "</html>";	
		
		$message = "$headers";
		$message .= "$sub_message";
	
					
		$posts = array($email,
					   $name,
					   $reason,
					   $comments);

	/**************************************************************************/
	// PROCESS
	//--------------------------------------------------------------------------
		require_once('captcha/recaptchalib.php');
		$privatekey = "6Le0bAUAAAAAAI_cz9eRYKpQEDw88CquozTmgT29 ";
		$resp = recaptcha_check_answer ($privatekey,
										$_SERVER["REMOTE_ADDR"],
										$_POST["recaptcha_challenge_field"],
										$_POST["recaptcha_response_field"]);
		
		if (!$resp->is_valid) {
		  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
			   "(reCAPTCHA said: " . $resp->error . ")");
		}

		else {
			if (!isset($_POST['submit'])) {
				die ("The form needs to be filled out");
				}
				
			foreach($posts as $key => $value) {
				if($value == "" || $value == NULL) {
					die ("All of the form values must be entered.");
					}
			}
					
			unset($value);
			
			mail("$sendto","$subject","$message");
			header("Location: http://www.whitworthgallery.org/thankyou.php?type=contact");
		}


It still sends in a big clump of text.

Quote

<html><head></head><body><h3>From: ME</h3><br><strong>Email:</strong> gkwinspired@gmail.com<br><strong>Reason:</strong> General<br><strong>Comments:</strong><br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean dolor. Mauris quis quam. Etiam ullamcorper hendrerit mi. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean viverra. Aliquam gravida, augue ut suscipit ultrices, turpis diam suscipit leo, vel varius orci tellus eget enim. Morbi viverra sem eu libero. Donec erat magna, viverra a, consectetur et, cursus vel, urna. Nunc sed enim. Nulla cursus est vel mi. Nulla facilisi. Maecenas elit libero, rhoncus non, bibendum ac, scelerisque eget, diam. Nulla eu nibh at lacus dictum viverra. </body></html>

Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,612
  • Joined: 23-August 08

Re: PHP Mail [** SOLVED **]

Posted 08 March 2009 - 05:27 PM

The mail function takes an optional parameter after the message which should contain the headers:
mail($sendto, $subject, $message, $headers);

Was This Post Helpful? 1
  • +
  • -

#9 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 219
  • View blog
  • Posts: 1,605
  • Joined: 20-January 09

Re: PHP Mail [** SOLVED **]

Posted 08 March 2009 - 08:23 PM

Thanks it works now.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1