Jump to content

Recommended Posts

When I put a newline (\n) into my strings which are later passed onto the $body variable, I actually see the literal "\n" in the email. The same goes for HTML code. Here's my code, note that the indentation looks off but is logical in my document:

<?php # Mail Script v1.0 by {me}

$to			= 'my email address;
$subject 	= 'Request for more information';
$mailheaders= 'From: Client's name-Website';

// Grab the form and assign to variables

$name		=	$_REQUEST['fName'] .' '. $_REQUEST['lName'];
$email		=	$_REQUEST['email'];
$company	=	$_REQUEST['company'];
$address1	=	$_REQUEST['address1'];
$address2	=	$_REQUEST['address2'];
$city		=	$_REQUEST['city'];
$state		=	$_REQUEST['state'];
$zip		=	$_REQUEST['zipCode'];
$phone		=	$_REQUEST['phone'];
$about		=	$_REQUEST['contactAbout'];

// Send the mail

$body = '<div style="font: 10pt arial; color: #333;">'.
		'<p>Someone has requested information from the website.</p>'.
		'<table border="0" cellpadding="3" cellspacing="0" style="font-size: 10pt;">'.
			'<tr><th align="left">Name:</th>		<td> '.$name.' </td></tr>' . 
			'<tr><th align="left">Email:</th>		<td> '.$email.' </td></tr>'.
			'<tr><th align="left">Company:</th>		<td> '.$company.' </td></tr>'.
			'<tr><th align="left">Address:</th>		<td> '.$address1.' </td></tr>'.
			'<tr><th align="left">Address 2:</th>	<td> '.$address2.' </td></tr>'.
			'<tr><th align="left">City:</th>		<td> '.$city.' </td></tr>'.
			'<tr><th align="left">State:</th>		<td> '. $state.' </td></tr>'.
			'<tr><th align="left">Zip:</th>			<td> '.$zip.' </td></tr>'.
			'<tr><th align="left">Phone:</th>		<td> '.$phone.' </td></tr>'.
			'<tr><th align="left">Regarding:</th>	<td> '.$about.' </td></tr>'.
		'</table>'.
	'</div>';

mail ($to, $subject, $body, $mailheaders);

header("Location: ../thanks.php");

?>

And the results:

<div style="font: 10pt arial; color: #333;"><p>Someone has requested information from the website.</p><table border="0" cellpadding="3" cellspacing="0" style="font-size: 10pt;"><tr><th align="left">Name:</th> <td> my name </td></tr><tr><th align="left">Email:</th> <td> my email </td></tr><tr><th align="left">Company:</th> <td> my company  </td></tr><tr><th align="left">Address:</th> <td>  </td></tr><tr><th align="left">Address 2:</th> <td>  </td></tr><tr><th align="left">City:</th> <td>  </td></tr><tr><th align="left">State:</th> <td> Virginia </td></tr><tr><th align="left">Zip:</th> <td>  </td></tr><tr><th align="left">Phone:</th> <td>  </td></tr><tr><th align="left">Regarding:</th> <td>  </td></tr></table></div>

Why is this? What am I doing wrong here?

Link to comment
https://forums.phpfreaks.com/topic/71720-formatting-mails-sent-with-php/
Share on other sites

in the last parameter of mail() you can specify headers. Here's what I use for HTML email:

 

"Content-Type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: 8bit\r\n\r\n";

 

be careful with headers, though. Don't use any raw site-visitor provided data there, or your mail form could become a spam portal.

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.