简体   繁体   中英

Line break html Email

new to the forum and trying my hand at some coding to help out a friend who cant seem to get this right..

with that being said, i was originally having issues with the contact form on a website not being able to send an email. after a bit of searching on the net and adding a few components here and there it is finally working, but now i have an additional problem..

when the email gets sent through (this is a business website and it sends an email from there to the relevant sales department etc) its all shoved into one line and looks terrible..

like this-

"Name: TEST EMAIL FROM WEBSITETel: 011 937 0572Email: myemail@zmail.comMessage: TEST PLEASE CONFIRM

test 38"

what i have not been able to find is how to seperate the text so that it comes through in an email as seperate lines like this-

Name: Client

Tel: 011 000 0000

Email: myemail@zmail.com

Message: text here etc.

i have linked the contact form to a .php document, so i would presume that it is in this document that the change would need to take place?? i have tried to add in <br /> & <div> but neither do anything except give me an error message when i try send form from the site.

here is the code for the contactgenie.php linked to the contact form that works 100%

<?php

$EmailFrom = "myeamail@zmail.co.za";
$EmailTo = "myemail@zmail.co.za";
$Subject = "Company Name - Online Enquiry";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));

// validation
$validationOK=true;
if (!$validationOK) {
  print "There has been an error, please make sure you entered a correct email address."; // You can edit this to your own error message
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "";

// send email
$success = mail($EmailTo, $Subject, $Body, $Headers = "From: <$EmailFrom\r\n");

// redirect to success page
if ($success){
  print "Thank you, your email has been sent! We will be in touch shortly!"; // You can edit this to your own success message
}
else{
  print "There has been an error, please make sure you have entered your details correctly."; // You can edit this to your own error message
}
?>

any help with this would be greatly appreciated, thanks Dillon

You could pre-format the mail body using standard line breaks within double quotes like this:

$Body = "
    Name: {$Name}
    Tel: {$Tel}
    Email: {$Email}
    Message: {$Message}";

To achive the double line-height you insert another return between the lines:

$Body = "
    Name: {$Name}

    Tel: {$Tel}

    Email: {$Email}

    Message: {$Message}";

thanks for all your help guys! i got it to work, i added "\\n" into the code and it works perfectly, i just need it to seperate the text so that it is easier to read when the email comes through from the site, thanks again really helped me out with this!

add <br/> tag to add new line space with your variables like this

   $Body = "";
$Body .= "Name: ";
$Body .= $Name.'<br/>';

and wherever else you want to add new line space for this your must be in HTML form because there are two type of email html and richtext. takecare of that also.

Not sure if this works but if it's HTML email, this should work.

$Body .= '<html><body>';
$Body .= "Name: ";
$Body .= $Name;
$Body .= "<br>";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "<br>";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "<br>";
$Body .= "Message: ";
$Body .= wordwrap($Message, 50);
$Body .= '</body></html>';

The message may or may not work. Don't get your hopes up to high on that part.

add <br/> tag to add new line space with your variables like this

$Body  = "Name   : " $Name    ."<br/>";
$Body .= "Tel    : " $Tel     ."<br/>";
$Body .= "Email  : " $Email   ."<br/>";
$Body .= "Message: " $Message ."<br/>";

不要使用 break 标记,它不起作用。您可以轻松地使用 "\\r\\n" 作为换行符

$Body = "Name : ". $name ."\r\n"."Email : " . $email ."\r\n"."Contact : " . $contact;

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