tamanna Posted May 22, 2014 Share Posted May 22, 2014 I want to do something like this, I had a html query submission form linked to php. I want to send the output generated after php execution to the user through mail id provided in the form, in a manner such that when user click submit button, he well be redirected to thank you page and php keeps on running in the background and as soon as the output is generated, it will be send to the end user through email. As my query takes time to execute, so I don't want the end user to keep waiting till the program gets finish. Here is my code: <?php$seq = $_POST['seq']; if (isset($_POST['seq'])) {$b = fopen("sequence.txt", "w");fwrite($b, $seq);fclose($b);system("perl /opt/lampp/htdocs/matepred/blast/bin/scriptforblastcompleterun.pl sequence.txt nr > out");system("perl /opt/lampp/htdocs/matepred/blast/bin/format.pl > output");system("perl /opt/lampp/htdocs/matepred/blast/bin/testing.pl output"); echo "<div align='center'><font color='blue'><b>RESULT</font></div>";$i=1;$files = array();foreach (glob("file_*.out")as $file){ $files[] = $file;$b = fopen("/opt/lampp/htdocs/matepred/blast/bin/$file", "r");$s=fgets($b);fclose($b);echo "<table border=10. align=center><tr bgcolor=lightgreen><th>SerialNo</th><th>Value</th><th>Decision</th><th></tr>";echo '<td>'. $i++. '</td>'; echo "<td>$s</td>";if($s>=0){echo "<td>Yes</td>";}else{echo"<td>No</td>";}echo "</table>";}} ?> html table part marked in red here is the output which I want to send back to the user. Can anybody help me in linking my php output to the mail. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/288673-sending-php-results-to-the-end-user-through-email/ Share on other sites More sharing options...
IanA Posted May 22, 2014 Share Posted May 22, 2014 It would be interesting to know a good solution to this. My first thoughts would be to have different threads handling this, one handling your presentation logic and another handling the e-mail side of things - I may be incorrect here, so will be best to wait for some of the more experienced developers to have their input. Quote Link to comment https://forums.phpfreaks.com/topic/288673-sending-php-results-to-the-end-user-through-email/#findComment-1480433 Share on other sites More sharing options...
tamanna Posted May 27, 2014 Author Share Posted May 27, 2014 I had saved the results in a text file and now trying to send these to the user via provided mail using localhost on ubuntu system. Code : $to=$_POST['email'];$subject='Your results';$body=$data; (//here $data stores the output file in text format)$from="http://localhost/matepred/blast/bin/new.php";mail( $from, $to, $subject, $body); But it isn't sending any mail. Can anyone help me to know the problem with the code. Or is this a problem with localhost? Quote Link to comment https://forums.phpfreaks.com/topic/288673-sending-php-results-to-the-end-user-through-email/#findComment-1480990 Share on other sites More sharing options...
IanA Posted May 27, 2014 Share Posted May 27, 2014 Do you have a working SMTP server running on your localhost also? The mail function won't simply send an e-mail for you unless you have SMTP set up too. There are some good free examples such as smtp4dev or fakesmtp that should help you get on your way. Quote Link to comment https://forums.phpfreaks.com/topic/288673-sending-php-results-to-the-end-user-through-email/#findComment-1480991 Share on other sites More sharing options...
boompa Posted May 27, 2014 Share Posted May 27, 2014 You should also consider using a third-party mail library like PHPMailer or SwiftMailer, which will ensure the mail is properly composed and avoid getting lost in anti-spam filters. Quote Link to comment https://forums.phpfreaks.com/topic/288673-sending-php-results-to-the-end-user-through-email/#findComment-1481008 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.