$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";
Related
Here is the interesting part, if I remove the $from code, it will properly render the html email like it supposed too. If I add the $from code back in, the $from will work properly but show the entire html script code in the body of the email. I am trying to figure out how to get the from and the html email to work properly together. I have tried the \n\r and \r but nothing works. It's one or the other with this code.
$from = 'MyOwnEmail';
$to = $email;
$subject = 'Test ';
$message_body = '<html><html>';
$headers = 'MIME-Version: 1.0';
$headers = 'Content-type: text/html; charset=iso-8859-1';
$headers = "From: $from";
mail( $to, $subject, $message_body, $headers);
$headers = 'MIME-Version: 1.0';
$headers = 'Content-type: text/html; charset=iso-8859-1';
$headers = "From: $from";
Each time you assign a new value to $headers, you replace the old value.
So you need to look up how to put multiple headers into the variable. See the documentation for the additional headers:
String to be inserted at the end of the email header.
This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.
So you still need a string, but it has to be one string with all the headers in it, and the need to be separated by new lines.
The cleanest way to do this would be to put all the headers in an array and then join them.
$header_list = [ 'MIME-Version: 1.0', 'Content-type: text/html; charset=iso-8859-1', "From: $from" ];
$header = implode("\r\n", $header_list);
Append headers instead of overwriting.
$headers = 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= "From: $from"."\r\n";
Solution - Fixed with Quentin Help -- Thanks
$from = 'MyOwnEmail';
$to = $email;
$subject = 'Test ';
$message_body = '<html></html>';
$header_list = [ 'MIME-Version: 1.0', 'Content-type: text/html; charset=iso-8859-1', "From: $from" ];
$header = implode("\r\n", $header_list);
mail( $to, $subject, $message_body, $header);
How can I prove to email clients that the sent email was sent from the domain which the email was sent from? I have included the code I use to send emails.
$headers = "From: noreply#mydomain.com\r\n";
$headers .= "Reply-To: noreply#mydomain.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$to = $_GET['to'];
$subject = $_GET['subject'];
$message = $_GET['message'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
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.
On sending a mail I've set my header to:
$headers = 'From: Tómas<tomas#email.com>'. "\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\n";
for mail($to, $subject, $message, $headers);
The Tómas is working in the content correctly but not in the from section of the email. It shows up like Tómas. Any idea how to modify the header to make this work?
Many thanks.
Tó = Tó
change the following line
$headers = 'From: Tómas<tomas#email.com>'. "\r\n";
with
$headers = 'From: Tomas<tomas#email.com>' . "\r\n";
My script send the email but it doesn't render the html tags. I'm not sure why not.
$email = $row['email'];
$mail_body = '<html>
<body>
<p>hello,'.$name.'</p>
<p>this is a testing email </p>
<hr />
<p>by server</p>
</body>
</html>';
$subject = "Better website";
$to = "$email";
$headers = "From: mailscript#hotmail.com\r\n";
$headers .= "Content-Type: text/html\r\n";
$mail_result = mail($to, $subject, $mail_body, $headers);
Try setting the mime type as well as shown in the manual for 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";
as Jrod already answered you need to add the header
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
but I found that this one is screwing mine up as of late and had to comment it out:
$headers = 'MIME-Version: 1.0' . "\r\n";