php - simple mail() which will generate a fetched report from mysql -
sending mail in php using simple mail()
function.
i want send mail generate report fetched mysql database mail()
expects 4 parameteresmail($to,$subject,$message,$from)
not able generate $message
hold body of mail fetched values , specific format.
my script.php
generate report:-
<?php $to = 'abc@gmail.com' . ', '; $subject = 'test mail'; $query=mysql_query("select * table_name "); echo'<html> <head> <title>testing</title> </head> <h1>test user</h1> <table border="1" cellspacing="1"> <tr> <th>id</th> <th>user</th> <th>phonecount</th>'; while($row = mysql_fetch_array($query)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['user'] . "</td>"; echo "<td>" . $row['phone'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "</html>"; $headers = 'mime-version: 1.0' . "\r\n"; $headers .= 'content-type: text/html; charset=iso-8859-1' . "\r\n"; // more headers $headers .= 'from: <from@example.com>' . "\r\n"; mail($to, $subject, $msg, $headers); ?>
as got value of $to, $subject, $headers $msg creating problem.how can send mail format.i cannot figure out how body of mail in $msg generate reports
well in it's simplest form instead of echo'ing content out want assigned variable.
you've got couple of options this:
1) variable concatination
$message = '<p>line 1</p>'; $message .= '<p>' . $line2 . '</p>'; $message .= '<p>line 3</p>';
the contents of $message be:
<p>line 1</p><p>line 2</p><p>line 3</p>
2) output buffering
ob_start(); // http://www.php.net/manual/en/function.ob-start.php echo '<p>line 1</p>'; echo '<p>' . $line2 . '</p>'; echo '<p>line 3</p>'; $message = ob_get_clean(); // http://www.php.net/manual/en/function.ob-get-clean.php
3) heredoc syntax (this approach can tricky wouldn't recommend right now)
$message = <<<eot <p>line 1</p> <p>$line2</p> <p>line 3</p> eot;
each of these 3 approaches let content assigned $message.
however default mail send plain text email. if want send html email need set specific headers , ideally should set multipart boundaries etc. i'd recommend using library zend's can include piecemeal. failing here's basic example: http://css-tricks.com/sending-nice-html-email-with-php/
hope helps.
Comments
Post a Comment