Jump to content

Php Html Email


tobyhutton

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][email protected][/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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.