简体   繁体   中英

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.

You need to specifically declare content type to to use html statements 内容类型才能使用html语句

$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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM