0

I am trying to send HTML code inside the mail function but unfortunately, the connection is established but the email is not sent...This is my code below please help me with it.

 <?php
 if($_SERVER['REQUEST_METHOD']=='POST'){

require_once('connect.php');
$userEmail = $_POST['myuserEmail'];
//print_r($userEmail);
$to=$userEmail;
$subject="Welcome Aboard| Judgement6";
$message="<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>A table as email</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Fname</td>
<td>Sname</td>
</tr>
</table>
</body>
</html>";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\b";
$headers = "From: judgement6ent@gmail.com" . "\r\n";
mail($to,$subject,$message,$headers);
echo 'email sent';

?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Vipul Singh
  • 163
  • 1
  • 3
  • 13
  • `"\r\b"` is not CRLF. – mario Oct 13 '18 at 00:46
  • could you please guide me with this@mario – Vipul Singh Oct 13 '18 at 00:47
  • @mario missed the missing dot for the 3rd header. Hey, it happens to the best of us too. I once and many years ago when I first started out in PHP, had spend the better part of almost 3/4 of an hour to see that a dot messed up my code I was trying. That needed to be a semi-colon so I must've fat-fingered it. So, fix those 2 things (edit: 3) & you should get the email. If not, you can edit your question by containing the new code that you tried, but don't overwrite the original code. Place the mail function in an `if/else` and see if it echos "sent" in an echo placed if the `if`; good luck. – Funk Forty Niner Oct 13 '18 at 00:58
  • Enable error reporting also. If the POST array has no value, then that will also contribute to it failing. Check if it's set/not empty and what I mentioned above. Edit: you have a missing brace also; error reporting would have thrown you something about that, given that that is your actual code. – Funk Forty Niner Oct 13 '18 at 00:59
  • ok let me check it. – Vipul Singh Oct 13 '18 at 01:00
  • btw, the way to ping someone correctly is `@username` with a space both left and right it. Always ping someone directly, I may have moved out of the question. – Funk Forty Niner Oct 13 '18 at 01:01
  • so basically i have to change ''\r\b" to ''\r\n" at header3 @FunkFortyNiner – Vipul Singh Oct 13 '18 at 01:04
  • After making few changes in header3, now I can send the emails and they are sent perfectly but eventually, the HTML code is not rendered, I mean the raw HTML lines is printed inside the email. – Vipul Singh Oct 13 '18 at 01:23
  • Could you help me with this @FunkFortyNiner – Vipul Singh Oct 13 '18 at 09:14
  • `$headers = "From:` has a dot missing => `$headers .= "From:...` and yes, the "b" to an "n". – Funk Forty Niner Oct 13 '18 at 12:29
  • it is working after adding that dot(.), now I have an HTML file which contains HTML, CSS, javascript in it so how do I add that in the message, I am posting the file in the question @FunkFortyNiner – Vipul Singh Oct 13 '18 at 13:42
  • So how could i add a big html to the message parameter.. @FunkFortyNiner – Vipul Singh Oct 13 '18 at 14:29
  • Why I can not send longer messages in message parameters?? @Funk Forty Niner – Vipul Singh Oct 14 '18 at 13:25
  • Specially which includes CSS in it – Vipul Singh Oct 14 '18 at 13:26

0 Answers0