0

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.

Brad
  • 159,648
  • 54
  • 349
  • 530
Annie
  • 39
  • 1
  • 7
  • Outlook likes to strip line breaks out. There should be an option to show line breaks. You can use
    instead that won't be strip.
    – Joshua Bixler Apr 11 '14 at 02:55
  • Show the command you are using to send the email (I'm not willing to presume you have set the content-type header). PHP_EOL is the end of line for the platform running PHP. –  Apr 11 '14 at 02:56
  • I just update the question with all the details, thanks. – Annie Apr 11 '14 at 03:04
  • @Annie You have a syntax error in your code. Can you clean up the code? And, show us the full e-mail source that gets sent with headers. – Brad Apr 11 '14 at 03:11
  • Hi Brad, I can send email through this code, so I think the syntax is fine just the line break part is not working. – Annie Apr 11 '14 at 03:13
  • 1
    The source of the actual message would be helpful for diagnostics. – tripleee Apr 11 '14 at 03:14

2 Answers2

1

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.

Jabran Saeed
  • 5,760
  • 3
  • 21
  • 37
-2

You need to <br> instead of \r\n because your content-type is text/html. Same question here: link

Community
  • 1
  • 1
hoangkianh
  • 631
  • 4
  • 13