Hi All,
I have a form set up on my web site sending HTML emails. I am using the phpMailer class to send emails. When I receive the emails I am experiencing an annoying problem trying to get paragraph breaks. I keep getting "\n\n\" where paragraph separations should be. I've tried
.nl2br($comments).
and
$comments = str_replace('\n.', '\n..', $comments);
But those annoying "n's" are still there. Could it be because I'm not declaring a MIME type? I have put the mail code below in case someone can see anything obvious.
$site_owner_email = 'me@mydomain.org';
$site_owner_name = 'My Name';
$comments = str_replace('\n.', '\n..', $comments);
$url = $_SERVER['HTTP_REFERER'];
$htmlBody = '<html>
<head>
<style type="text/css" media="screen">
body {font-family:arial, verdana, sans-serif; background-color: #e3e3e3; font-size: 1em; height: 100%;}
h3 {font-size: .9em; color:#333333; margin-bottom: 1em; margin-left: .45em;}
p {color: #666; font-size: .75em; margin-left: .5em; line-height: 1.3em; margin-bottom:1em;}
ul li {list-style:none; font-size: .75em;}
</style>
</head>
<body>
<div style="overflow: hidden; background-color: #e3e3e3; width: 59em;">
<div style="width: 100%; background-color: #fff; border: 1px solid #ccc; margin: auto;">
<div align="center"><img src="http://www.mydomain.org/images/pageElements/header.jpg" title="Welcome To Massachusetts Cicadas" alt="Welcome To My Domain"" style="height: 190px; width: 950px"></div><br>
<h3>A Contact Request Has Come Through. Below is the Information.</h3>
<p>User Details:</p>
<ul>
<li><b>Name: </b>'.$name.'</li>
<li><b>Email: </b>'.$email.'</li>
<li><b>Website: </b>'.$website.'</li>
</ul>
<p>User Comments:</p>
<p><em>'.$comments.'</em></p>
</div>
</div>
</body>
</html>';
$textBody = 'Name:'.$name."\r\n" .
'Email:'.$email."\r\n" .
'Website:'.$website."\r\n\n".
'This is the comment:'."\r\n".$comments."\r\n\n" .
require_once('../PHPMailer_v5.1/class.phpmailer.php');
$mail = new PHPMailer ();
$mail -> IsSMTP ();
$mail -> From = $email;//who filled out the form email
$mail -> FromName = $name;//who filled out the form name
$mail -> Subject = 'Inquiry From My Domain Contact Form.';
$mail -> AddAddress($site_owner_email, $site_owner_name);//message goes to webmaster
$mail -> Body = ($htmlBody);
$mail -> isHTML(true);
$mail -> AltBody = ($textBody);
$mail -> Host = "mail.mydomain.org";
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail -> Port = 25;
$mail -> SMTPAuth = true;
$mail -> Username = "me@mydomain.org";
$mail -> Password = "mypassword";
$mail -> send();
echo '<li class="success"> Congratulations, ' . $name . '. Your message was posted successfully! We will get back to you shortly. </li>';
}
Thanks for any help.
Gerry