Break wp_mail breaks in textarea for html email
I am having a problem using wp_mail function and hope someone can help me.
I need to insert line breaks in an email added by the user to a textbox. '
Can anyone please help?
I currently have the following code sending an email from a contact form:
<?php
if( !isset($_REQUEST) ) return;
require('../../../../wp-load.php');
function wpse27856_set_content_type(){
return "text/html";
}
add_filter( 'wp_mail_content_type','wpse27856_set_content_type' );
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$msg = $_REQUEST['message'];
$headers = 'From: '.$name.' <'.$email.'>' . "\r\n";
$message = '
<html>
<body>
Someone has made an enquiry on the online contact form:
<br /><br />
<b>Contact Details:</b><br />
'.$name.'<br />
'.$phone.'<br />
'.$email.'<br /><br />
<b>Message:</b><br />
'.$msg.'<br />
<br /><br />
</body>
</html>
';
wp_mail('email@email.co.uk', 'Contact form Message' , $message, $headers);
?>
+3
source to share
4 answers
By default, wp_mail () sends messages in plain text, so HTML is not processed by email clients.
Include the following email headers:
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
Since your email is in HTML, it is always good practice to make it valid with the correct HTML template (HTML, HEAD, BODY ...)
Alternatively, you can replace your tags with carets (\ r \ n), although you still need to get rid of the tags.
This is already covered in the PHP documentation for mail (), which wp_mail () wraps around.
+4
source to share
use this header to send html by email
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\n";
$headers .= "X-Priority: 1 (Higuest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
$headers .= "From: Approprice <".$mailfrom.">" . "\n";
$headers .= "Return-Path: Approprice <".$mailfrom.">" . "\n";
$headers .= "Reply-To: Approprice <".$mailfrom.">";
+1
source to share