How to add css style in php email? - php

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.

Related

Mail getting with HTML tags

My mail function is working fine, delivering mail after filling the form.
But the output in the mail is with HTML tags as shown attached.
Here is my code.
<php if (isset($_REQUEST['email'])) {
$admin_email = "abcdef#gmail.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['salespersonname'];
$location = $_REQUEST['location'];
$noofbags = $_REQUEST['noofbags'];
$print = '<div>Location : $location<br />No of Bags : $noofbags</div>';
$comment = $print;
mail($admin_email, "$subject", $comment, "From:" . $email);
echo "Thank you for contacting us!";
}
?>
How can i get Output like this.
Location : Hyderabad
No of Bags : 50
Use the below Headers to send email with HTML tags:
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
Updated Code:
<php if (isset($_REQUEST['email'])) {
$admin_email = "abcdef#gmail.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['salespersonname'];
$location = $_REQUEST['location'];
$noofbags = $_REQUEST['noofbags'];
$print = '<div>Location : $location<br />No of Bags : $noofbags</div>';
$comment = $print;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($admin_email, "$subject", $comment, "From:" . $email, $headers);
echo "Thank you for contacting us!";
}
?>
Hope this will be help.
you have to set header's
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
mail($to, $subject, $message, $headers);
Add following headers :
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Pass $headers as 4th parameter in mail function.
You need to set the Content-type header in your email message:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
and pass into
mail($admin_email, "$subject", $comment, "From:" . $email, $headers);
Your message body also needs to be contained in <html> tags.

sending mail from php when link in message body

i have a php script
<?php
$to = 'somebody#somedomain.com';
$subject = 'Test mail';
$message = 'mysitedomain.com';
$from = 'support#mysitedomain.com';
$headers = 'From:' . $from;
mail($to,$subject,$message,$headers);
echo 'Mail Sent.';
?>
When i run this code mail not send. If i change message to mysitedomaincom (without dot before com) the mail send succesfull.
Anybody have a solution for this?
This codes that tells the mailer and the recipient that the email contains well formed HTML that it will need to interpret
If you want you can change content of $message, now with this codes you can send HTML content mail.
<?PHP
$to = 'somebody#somedomain.com';
$subject = 'Test mail';
$headers = "From: Support <support#mysitedomain.com>" . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<h1>mysitedomain.com</h1>';
$message .= '</body></html>';
mail($to, $subject, $message, $headers);
?>

PHP - Not receiving email from contact form

I am not receiving emails from this contact form, but the message seems to sending okay and it also redirects me to the sent page.
I don't have access to the server only via FTP.
PHP
<?php
$to = 'test#gmail.com';
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$body = <<<EMAIL
<html>
<p><h3>Email Submited From Website.</h3></p>
<p><strong>Name:</strong> $name</p>
<p><strong>Email:</strong> $email</p>
<p><strong>Subject:</strong> $subject</p>
<p><strong>Message:</strong> $comment</p>
</html>
EMAIL;
// 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";
// Additional headers
$headers .= 'To: test email' . "\r\n";
$headers .= 'From: <website#mt.co.uk>' . "\r\n";
//$headers .= 'Cc: noreply#example.com' . "\r\n";
//$headers .= 'Bcc: noreply#example.com' . "\r\n";
if ($_POST['submit']){
mail($to, $subject, $body, $headers);
header ("Location: message-sent.php");
die();
} else {
header ("Location: message-failed.php");
die();
}
?>
Check if mail is actually being sent:
if (mail($to, $subject, $body, $headers)===false) {
echo "Not sent!";
} else {
echo "Sent!";
}
Change this:
$headers .= 'To: test email' . "\r\n";
$headers .= 'From: <website#mt.co.uk>' . "\r\n";
To this:
$headers .= "To: $to <test email>\r\n";
$headers .= "From: website#mt.co.uk <website#mt.co.uk>\r\n";
Also, you need to sanitize the subject and body of the email so that the email arrives, but this will usually be reflected in the results after email() reports a success, in that case the email will bounce, go to the spambox, or simply be refused.
If your hosting provider doesn't have an email server, you could try to use a free email server and phpMailer. https://github.com/PHPMailer/PHPMailer

how to i send bcc or cc email in my mail function but i have tried code but bcc or cc function is not working? [duplicate]

i want to use bcc or cc function in this mail function?
Here My Mail Function
<?php
//SENDS EMAIL THAT TELLS THE USER TO ACTIVATE THE ACCOUNT
$activation = 'activation.php?key='.$key;
$your_email = 'non-reply#mydomain.pk'; //CHANGE TO YOUR SETTINGS
$domain = $_SERVER["HTTP_HOST"]; //YOUR DOMAIN AND EXTENSION
$to = $email;
$subject = 'MyDomain Activate Account';
$message .='<img src="http://mydomain.com/images/securedownload.jpg"/>';
$message = 'Welcome,<br/> '.$_POST['username'].'. You must activate your account via this message to log in. Click the following link to do so: http://'.$domain.'/'.$activation;
$headers = 'From: Mydomain<'.$your_email.'#'.$domain.'>\r\n'; //MODIFY TO YOUR SETTINGS
$headers .= 'Content-type: text/html\r\n';
mail($to, $subject, $message, $headers);
?>
You should add to the to and headers part of the mail.
For TO part
$to = "to#to.com, cc#cc.com"
For HEADERS part
$headers .= "To: To Name <to#to.com>\n";
$headers .= "CC: CC Name <cc#cc.com>\n";
$headers .= "BCC: BCC Name <bcc#bcc.com>\n";
It is very simple, just sharing if anyone gets help from here:
//......
//...Other setting goes here....
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: My Name <myemail#example.com>'. "\r\n";
//Multiple CC can be added, if we need (comma separated);
$headers .= 'Cc: myboss1#example.com, myboss2#example.com' . "\r\n";
//Multiple BCC, same as CC above;
$headers .= 'Bcc: myboss3#example.com, myboss4#example.com' . "\r\n";
mail($to, $subject, $message, $headers);
Just add the Bcc/CC in your Code
<?php
//SENDS EMAIL THAT TELLS THE USER TO ACTIVATE THE ACCOUNT
$activation = 'activation.php?key='.$key;
$your_email = 'non-reply#mydomain.pk'; //CHANGE TO YOUR SETTINGS
$domain = $_SERVER["HTTP_HOST"]; //YOUR DOMAIN AND EXTENSION
$to = $email;
$subject = 'MyDomain Activate Account';
$message .='<img src="http://mydomain.com/images/securedownload.jpg"/>';
$message = 'Welcome,<br/> '.$_POST['username'].'. You must activate your account via this message to log in. Click the following link to do so: http://'.$domain.'/'.$activation;
$headers = 'From: Mydomain<'.$your_email.'#'.$domain.'>\r\n'; //MODIFY TO YOUR SETTINGS
$headers .= "BCC: email#domain.com;\r\n"
$headers .= 'Content-type: text/html\r\n';
mail($to, $subject, $message, $headers);
?>

formatting email in php?

$to = "$email";
$subject = "Thank You";
$message = "<p>Thanks for applying</p>";
$from = "solomon#kornar.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
when i send this email to myself, i still see the html tags, why is this thanks!!
You need to send the Content-type header as text/html.
For example, change the $headers line to
$headers = "From: $from";
$headers .= "\nContent-type: text/html";
You need to set your headers content type. Like:
$headers.= 'Content-type: text/html; charset=UTF-8' . "\r\n";

Categories