Send subscribe email as email body not as text in php - php

I want to send the email to the email subscriber , here is my approach
$msg= file_get_contents("activate-mailer.html");
$from = $_POST['sunscribeemail']; // this is the sender's Email address
$subject = "Email Subscription for the news letter ";
$message = from . " " . Subscribe for the news letter:" . "\n\n" ;
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: " . $from;
$headers[] = "Reply-To: " . $from;
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to,$subject,$msg,implode("\r\n", $headers));
Email sent to subscriber successfully but it is sending html as text like <html>..</html> but i want to render this html to the email body.

Simply change the Content-Type from text to html
$headers[] = "Content-type:text/html;charset=UTF-8";

Related

$headers not working on centos

I have a simple mail function:
$to = 'someone#somedomain.com';
$cc = 'someother#somedomain.com';
$bcc = 'someotherother#somedomain.com';
$sub = 'Some Subject';
$body = $html;
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=iso-8859-1";
$headers[] = "From: Fancy Name <from#email.com>";
$headers[] = "Reply-To: Fancy Name <from#email.com>";
$headers[] = 'CC: '. $cc;
$headers[] = 'BCC: '. $bcc;
mail($to, $sub, $body, implode("\n", $headers));
this works on windows but not on CentOS - the logs return "Envelope From address apache#host is't allowed" (or something similar).
Looked into that and as a 5th param you can pass -f from#email.com and this does work. But it doesn't show as Fancy Name, it shows the email address - how can I either get headers to work properly or pass a name to the -f param?
Thanks
Found a solution:
do the headers as your would and in the 5th param do -f email#domain -F "Sender Name" e.g.
$to = 'someone#somedomain.com';
$cc = 'someother#somedomain.com';
$bcc = 'someotherother#somedomain.com';
$sub = 'Some Subject';
$body = $html;
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=iso-8859-1";
$headers[] = "From: Fancy Name <from#email.com>";
$headers[] = "Reply-To: Fancy Name <from#email.com>";
$headers[] = 'CC: '. $cc;
$headers[] = 'BCC: '. $bcc;
mail($to, $sub, $body, implode("\n", $headers), '-f from#email.com -F "Fancy Name"');
try to run this snipt of code and let me know
mail ('user#to-email.com', "Testing Mail Server", "This is a test email from CentOS web server", null, "-f user#from-email.com");

postfix send email subject breaks the FROM

I am using postfix to send an email to the user, but the problem is it breaks the words where it finds the space.
Here is the screenshot:
postfix-send-email
PHP code to send an email:
<?php
$subject = "Status Of mail";
$message = "Test Email using Postfix Apache2";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: 'The Travel Worthy' 'pathik#gmail.com"\r\n";
$send = mail('test#yahoo.com', $subject, $message, $headers);
if($send)
{
return 1;
}
else
{
return 0;
}
?>
Try replacing
$headers .= 'From: 'The Travel Worthy' 'pathik#gmail.com"\r\n";
with
$headers .= "From: The Travel Worthy <pathik#gmail.com>\r\n";

Adding CC in PHP mail function

I want to send mail with CC. The email is sent successfully, but CC is not sent.
$to = 'abc#xyz.com';
$subject = 'Order Details of Order Number:'.$orderID;
$headers = "From: webmaster#xyz.com\r\nReply-To: webmaster#xyz.com";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
$message = "Test Message";
$headers .= 'Cc: def#xyz.com' . "\r\n";
mail($to, $subject, $message, $headers);
I am sending this mail as HTML.
Add the header as following,
$to = 'toemailaddress#testcom';
$from = 'fromemail#from.com';
$fromName = 'FromName';
$subject = "Email Subject";
$htmlContent = "<h> content of the email </h>";
$headers = "From: $fromName" . " <" . $from . ">" . "\r\n";
$headers .= "Cc: cc#cc.com ";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//multipart boundary
$message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" ."Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n";
$returnpath = "-f" . $from;
$message .= "--{$mime_boundary}--";
$mail = #mail($to, $subject, $message, $headers, $returnpath);
Try add this code in the following order:
$headers = "From: $from_email\r\nReply-To: $from_email";
$headers .= 'Cc: test#test.com\r\n';
$headers .= 'Bcc: test#test.com\r\n';
$headers .= "Return-Path: <info#premierinspectiontn.com>\r\n";
//add boundary string and mime type specification
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
Resource

Add bold text in mail sender text

Here is the code:
$email_body = "You have received a new message. ".
" Here are the details:\n\n Name: $name \n Email: $email_address \n Message \n $message";
I want to add bold text to: "Name:", "Email:", and "Message"
I have tried using the "< b > name: < /b>" (without space of course), but it doesn´t work. I want the text to be bold when i receive the mail.
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$email_body = "You have received a new message. ".
" Here are the details:\n\n <strong>Name:</strong> $name \n <strong>Email:</strong> $email_address \n Message \n $message";
// Mail it
mail($to, $subject, $message, $headers);
You need To Set Header Content Type Like This:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Here is Example ....
<?php
$to = 'recivermail#email.com';
$subject = 'Your Subject';
$from = 'sender#email.com';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Your Title</h1>';
$message .= '<b style="color:#080;font-size:18px;">How Are You?</b>';
$message .= '</body></html>';
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>

How to add css style in php email?

How can i add tag inside the email php ? for instance , i want to bold my $for_pass .Any idea ? thanks
$subject = "Password Recovery";
$message = "Hi! Your member password is <strong>$for_pass</strong>";
$from = "smilepartyplanner2014#gmail.com";
$headers = "From:" . $from;
// send mail
$mail_sent = #mail( $forgot_email, $subject, $message,$headers );
//echo "Thank you for sending us feedback";
?>
<script>
alert("Your password has been sent to your email address. ");
</script>
<?php
You need send MIME headers in your mail to tell its HTML, as follows:
$headers = "From:" . $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$mail_sent = #mail($forgot_email, $subject, $message, $headers);
As you have it in the mail body but you need to declare content type on header
...
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From:" . $from;
the message body can have any inline styling you wish.

Categories