phpemailpearpear-mail

Plain text email next line doesn't work even with "\r\n"


Here is my code in php mail:

<?php
include_once("Mail.php");

$From = $_POST['enquiryemail'];
$To = $row2['email'];
$Subject = "An enquiry";
$Message = "This enquiry is created by: ".$_POST['enquiryname']."\r\nOrganization: ".$row['orgname']."\r\n Telephone Number: ".$_POST['telenum']."\r\nE-mail address: ".$_POST['enquiryemail']."\r\nMessage: ".$_POST['detail'];
address: ".$_POST['enquiryemail']."\r\nMessage: ".$_POST['detail'];
$Host = "smtp.test.com";
$Username = "";
$Password = "";

$Headers = array ('From' => $From, 'To' => $To, 'Subject' => $Subject);
$SMTP = Mail::factory('smtp', array ('host' => $Host, 'auth' => false,
'username' => $Username, 'password' => $Password));

$mail = $SMTP->send($To, $Headers, $Message);

and here is the result which "\r\n" doesn't work for 2 lines in the middle:

This enquiry is created by: testing Organization: testing Telephone Number: 123456 E-mail address: test@hotmail.com Message: test

Any idea how to make this works? Thanks.


Solution

  • You need to specifically declare content type to html to use html statements

    $message_string = "\r\n";
    $message_string .= 'Content-Type: text/html; charset=ISO-8859-1"';
    $message_string .= "\r\n";
    $message_string .= $Message;
    

    Now your break statements will take effect.