Jump to content

Recommended Posts

Hi there,

 

I'm not really a php person more asp.

 

I have to write an html send mail script. The email sends and receives perfect.

 

When a user writes the message in the <textarea> box I need to be able to write a new line, so when they press enter and blank line will show in the textarea, how can I write <br> for every blank line.

 

Heres my code so far.....

 

<?php

$from = $_POST['email'];
$to = "[email]person@domain.com[/email]";
$subject = $_POST["subject"];
$name = $_POST['name'];
$location = $_POST['location'];
$message = $_POST['message'];
$HTML = "<font size=2 face=arial><b><u>" . $name ." from " . $location . "</font></u></b>";
$HTML = $message

sendHTMLemail($HTML,$from,$to,$subject);


function sendHTMLemail($HTML,$from,$to,$subject)
{

    $headers = "From: $from\r\n"; 

    $headers .= "MIME-Version: 1.0\r\n"; 
    
    $boundary = uniqid("HTMLEMAIL"); 
    
    $headers .= "Content-Type: multipart/alternative;".
                "boundary = $boundary\r\n\r\n"; 

    $headers .= "This is a MIME encoded message.\r\n\r\n"; 

    $headers .= "--$boundary\r\n".
                "Content-Type: text/plain; charset=ISO-8859-1\r\n".
                "Content-Transfer-Encoding: base64\r\n\r\n"; 
                
    $headers .= chunk_split(base64_encode(strip_tags($HTML))); 

    $headers .= "--$boundary\r\n".
                "Content-Type: text/html; charset=ISO-8859-1\r\n".
                "Content-Transfer-Encoding: base64\r\n\r\n"; 
                
    $headers .= chunk_split(base64_encode($HTML)); 

    mail($to,$subject,"-f",$headers);
    
}

?> 

 

The $message is the message the user writes.

 

Any Thoughts

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/234682-php-html-email/
Share on other sites

No.. that would just print the code onto the page in your browser. You have to join your html with what nl2br outputs:

$HTML = "<font size=2 face=arial><b><u>" . $name ." from " . $location . "</font></u></b><br><br>\n";
$HTML .= nl2br($_POST['message']);

Don't know if you know about string concatenation so here's a link on what it is: http://php.net/manual/en/language.operators.string.php

Link to comment
https://forums.phpfreaks.com/topic/234682-php-html-email/#findComment-1206118
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.