send html in an email via php, can't seem to do it -
i have list of subscribers trying send html type email (essentially news letter). currently, sending plainly , can't seem figure how make better.
i've searched through other questions can't seem apply answers own code, help? code shown below:
<?php $user = "example"; $password = "example"; $host = "example"; $dbase = "example"; $table = "example"; $from= 'example';//specify here address want email sent $subject= $_post['subject']; $body= $_post['body']; // connection dbase $dbc= mysqli_connect($host,$user,$password, $dbase) or die("unable select database"); $query= "select * $table"; $result= mysqli_query ($dbc, $query) or die ('error querying database.'); while ($row = mysqli_fetch_array($result)) { $firstname= $row['firstname']; $lastname= $row['lastname']; $email= $row['email']; $msg= "dear $firstname $lastname,\n$body"; mail($email, $subject, $msg, 'from:' . $from); echo 'email sent to: ' . $email. '<br>'; } mysqli_close($dbc); ?>
so have message box can type message how make message box, html style? can add in h2 etc tags? or make email html newsletter
- i have put example in on purpose
you need send headers html declared: example
$to = 'person@example.com'; $subject = 'your subject'; $headers = "from: " . strip_tags($_post['req-email']) . "\r\n"; $headers .= "reply-to: ". strip_tags($_post['req-email']) . "\r\n"; $headers .= "cc: you@example.com\r\n"; $headers .= "mime-version: 1.0\r\n"; $headers .= "content-type: text/html; charset=iso-8859-1\r\n"; $message = // html code here mail($to, $subject, $message, $headers);
Comments
Post a Comment