How to send HTML mail in PHP with BOOTSTRAP formatting - php

What's the best way to construct and send an HTML email using mail()with bootstrap formatting?
I've tried the following example (not full code):
$msg = "
<html>
<head>
<link href = '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css' rel='stylesheet' type='text/css'>
</head>
<body>
<p>This is a request to reset your password</p>
<a href='blah'>Click here to reset your password.</a>
<button type='submit' class='btn btn-info btn-sm'>Reset</button>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=iso-8859-1"."\r\n"; "X-Mailer: php".
$headers .= 'From: Password Reset <passwordreset#blah.co.uk>' . "\r\n";
The mail sends and is received in html but not formatted.

Unless you put all of the bootstrap code directly in your email, no. Email clients remove remote files by default to prevent user tracking. You cannot code around this.

Related

How to send a webpage retrieved form the database as an email to multiple emails

I have a registration page, after the the registration the form will be generated to the applicant(containing all the form field which was filled by each applicant) which i retrieved form the database, Now i want the generated form to be send as a mail to multiple emails (which was provided by the applicant during the registration.
Here is the code for the form Retrieval and its responding i just want this page to be send as a mail to multiple emails like i stated above.
Thank you.
<?php
$query = "";
include("includes/connect.php");
?>
<?php
if(isset($_GET['name1'])) {
$sql = "SELECT *FROM intern_form WHERE unique_no='".$_GET['name1']."';";
$row = mysql_fetch_array(mysql_query($sql));
}
?>
<p>The Registrar,</p>
<p><?php echo $row['institution']; ?></p>
<p><?php echo $row['institution_address']; ?></p>
<p align="center"><strong>RE: APPLICATION FOR <?php echo $row['it_duration']; ?> INDUSTRIAL TRAINING:</strong></p>
Dear Sir/Ma,
This is to inform you that the above named student has been accepted for industrial attachment.
I hereby comfirm that we would be in a position to offer Industrial Training in our Directorate(ITeMS).
Please find attached schedule of duty during the attachment.
Thank You.
Yours faithfully,
Signature
<?php
// send to multiple emails
$to = 'friend1#example.com' . ', '; // first
$to .= 'friend2#example.com' . ', '; // second and other (with .=)
$subject = "Thanks for register";
$message = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Thanks for register</title>
</head>
<body>
<p>Dear Sir/Ma,</p>
<br>
<p>This is to inform you that the above named student has been accepted for <p>industrial attachment.</p>
<br>
<p>I hereby comfirm that we would be in a position to offer Industrial Training in our Directorate(ITeMS).</p>
<br>
<p>Please find attached schedule of duty during the attachment.</p>
<br>
<p>Thank You.</p>
<p>Yours faithfully,</p>
<p>Signature</p>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=utf-8 \r\n";
$headers .= "From: yournick <yournick#example.com>\r\n";
$headers .= 'Cc: secondnick#example.com' . "\r\n"; // if you want to send a copy to yourself or anybody
mail($to, $subject, $message, $headers);
?>

Customers email displays HTML tags on PHP system generated mail

When I send a really basic HTML email via a file using PHP mail it displays perfectly for me. But for my client he sees all the HTML tags in the email.
I have my own dedicated server, to try to problemsolve I ran the exact same file from a Heart Internet shared server I have and the email displayed perfectly to my client (no HTML tags) so it points to something to do with the server.
<?php
$to = 'tom#myemailaddress.com';
$subject = 'TOM Testing: HTML displaying correctly?';
$message = '
<html>
<head>
<title>This is a test</title>
</head>
<body>
<p>To see if</p>
<table>
<tr>
<th>You</th><th>See</th><th>The</th><th>HTML</th>
</tr>
<tr>
<td>or</td><td>it</td><td>is</td><td>formatted</td>
</tr>
<tr>
<td>correctrly</td><td>1</td><td>2</td><td>abc</td>
</tr>
</table>
</body>
</html>
';
// 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";
// Mail it
mail($to, $subject, $message, $headers);
?>
Here is my php info: http://www.saloponline.co.uk/phpinfo.php

Sending Mail through PHP

Here i have a problem when iam sending a mail.It is delevering properly but when iam trying designing the message body with HTML tags it sending the same html tags to my email inbox.How can i overcome this please tell me.
Here the PHP code:
$to = "$email";
$subject = "Test mail";
$message = '<!Doctype html><html><head><title>Confirm Link</title></head><body><div style="color:blue">Thank u for registering with us </div>
<div> Hi'.$name.' Please click the below link to activate your accont</div><div>Active your account now</div> </body></html>';
$from = "abc#gmail.com";
$headers = "From:" . $from;
Here my deliverd email inbox message:
here designing not working it display same as my program code.Please help me.
Confirm LinkThank u for registering with us
HiSrinivas Please click the below link to activate your accontActive your account now
// 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";
Note:
If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package ยป PEAR::Mail_Mime.
Reference
Send an HTML email:
<?php
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
The problem may be that you are not setting the mail headers. Try this:
// 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";
mail($to, $subject, $message, $headers);

how to send image mailer using php mail function

i am trying to send html image mailer using php mail function on linux platform. There is one issue when i am trying to send simple html content then it successfully get delivered to its subscriber. but when i try to send emailer which contains few images then it fails to deliver it. below are two codes 1 by which simple html is delivered. 2 which is not getting delivered.
<?php
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
code 2:
<?php
//change this to your email.
$to = "abhinav#xyz.in";
$from = "abhinav.1#gmail.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message= <<<EOF
<html>
<body bgcolor="#DCEEFC">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color="red">Thanks Mohammed!</font> <br>
* maaking.com
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>
EOF;
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa#p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email#maaking.cXom[/email]";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
I corrected the code by which I am able to send image mailer below is the code:
<?php
$to= 'abhinav#xyz.com' . ',';
$to .= 'abhinav#gmail.com';
$sub='test1';
$msg= <<<EOF
<html>
<body>
<table>
<tr>
<td><img src="http://d32vlg867bsa1v.cloudfront.net/z/prod/w/2/i/zovi-logo2.png" />
</td>
</tr>
</table>
</body>
</html>
EOF;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: <centos_test#example.com>' . "\r\n";
mail($to,$sub,$msg,$headers);
?>
I am still working to sent highly customized mailer and will describe how it can once I found how it can be done.

Why doesn't this php mail script work?

I made a php script that sends mail. It worked fine until i changed it so it sent stuff as html instead of just plain text. However, it isn't working. The script itself returns a success, but I'm not getting the email. I've checked my spam folder. Could anyone see why this isn't working? Thanks
<?php
$to = $_POST["mail"];
$subject = 'Registration at Campatet';
$message = '
<html>
<head>
<title>Registration at Campatet</title>
</head>
<body>
<p>Thank you for registering at Campatet!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: no-reply#campatet.com" . "\r\n";
if(mail($to, $subject, $message, $headers)){
echo "Success sending e-mail to: <b>".$to."</b>";
}
else{
echo "There was a error";
}
?>
Use this as your only header:
$headers = "Content-type: text/html; From: no-reply#campatet.com";
First, try removing the line
$headers = "MIME-Version: 1.0" . "\r\n";
Are you sure that the post variable is receiving it's address correctly? Try removing that and replacing it with the email address you are trying to use.
Have you ever been able to successfully send mail from your website at all?
Specifying email headers without a Reply-To header is often considered as reason to suspect spam. It doesn't matter that you don't want replies, just specify the Reply-To header.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= 'From: no-reply#campatet.com' . "\r\n" . 'Reply-To: no-reply#campatet.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();

Categories