linux1880 Posted December 14, 2007 Share Posted December 14, 2007 ?php $to = "me@headache.com"; $subject = "hi how are you"; $body = "helllo hello this is test.. this is test ........"; $headers = "From: mail@mail.co.uk\r\n" . "X-Mailer: xxxx LONDON"; if (mail($to, $subject, $body, $headers)) { echo("<p>Message sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> Hello friends, I want to send this email to different users. I already have variables like emails: <?=$row['email_add'] ?> body: <?=$row['noteforstudents'] ?> I just want different person to receive email according to the details above. Do I need to set up session or require_once for this ? I don't know how to setup pls help Thanks Edit/Delete Message Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 14, 2007 Share Posted December 14, 2007 Well, just use the variable in the body and to attributes. Also, please post in the correct forum and use the tags around code Quote Link to comment Share on other sites More sharing options...
linux1880 Posted December 14, 2007 Author Share Posted December 14, 2007 Sorry I am new and didn't know where to post. but how do i add variable in body ? just like $body = "<?=$row['noteforstudents'] ?>"; I did that and it didn't work Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 14, 2007 Share Posted December 14, 2007 You'd do $body = $row['noteforstudents']; <?=$row['noteforstudents']?> is shorthand for <?php echo $row['noteforstudents'] ?> (see: http://php.net/echo) Quote Link to comment Share on other sites More sharing options...
linux1880 Posted December 14, 2007 Author Share Posted December 14, 2007 I did try <?php $to = "webmaster@placett.co.uk"; $subject = "You have received feedback from LONDON"; $body = $row['noteforstudents']; $headers = "From: an@angliancollege.co.uk\r\n" . "X-Mailer:LONDON"; if (mail($to, $subject, $body, $headers)) { echo("<p>Message sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> There is nothing on the message body, how ever, when i just type plain text like "hellow how are you". It goes, dunno what's happening Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 14, 2007 Share Posted December 14, 2007 Where does the $row variable come from? Quote Link to comment Share on other sites More sharing options...
linux1880 Posted December 14, 2007 Author Share Posted December 14, 2007 Hi danny, I have another php page which extact the data from the database with this command <?=$row['noteforstudents'] ?> I thought the same thing will pull out the same information from the database to the email but it's not happening. I put $row as you have taught me but doesn't seem to work Quote Link to comment Share on other sites More sharing options...
linux1880 Posted December 15, 2007 Author Share Posted December 15, 2007 anyone there please ? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 15, 2007 Share Posted December 15, 2007 I supposed you had already fetched some data and stored it as an array in $row. Although you can do so you'll fetch it just by doing that it wouldn't be a good idea and I doubt that you've done so. You'll have to get the data from the database like you did on the other page. Quote Link to comment Share on other sites More sharing options...
JamieThompson90 Posted December 15, 2007 Share Posted December 15, 2007 Wrong Topic.Delete please. Quote Link to comment Share on other sites More sharing options...
linux1880 Posted December 17, 2007 Author Share Posted December 17, 2007 Thank you sir, $body = $row['noteforstudents']; This code did work on the same page as there are other codings and the mail goes everytime the page refresh. But when i move this page to another php page like something.php it doesn;t pull the data from the database, any help would be greatful <?php $to = "memem@gmail.com"; $subject = "This is a email feedback from me"; $body = $row['noteforstudents']; $headers = "From: ashfh@djd.co.uk\r\n" . "X-Mailer: xxxx LONDON"; if (mail($to, $subject, $body, $headers)) { echo("<p>Message sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 17, 2007 Share Posted December 17, 2007 Is that the only code on that page/in that file? Quote Link to comment Share on other sites More sharing options...
linux1880 Posted December 17, 2007 Author Share Posted December 17, 2007 yes sir Quote Link to comment Share on other sites More sharing options...
linux1880 Posted December 17, 2007 Author Share Posted December 17, 2007 If insert the above php mail block code on the original page which has got other variables and forms that mail thing work but when i create another page sendmail.php of this mail and insert the code <?php $to = "memem@gmail.com"; $subject = "This is a email feedback from me"; $body = $row['noteforstudents']; $headers = "From: ashfh@djd.co.uk\r\n" . "X-Mailer: xxxx LONDON"; if (mail($to, $subject, $body, $headers)) { echo("<p>Message sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> I get empty message . It would be no problem if the mail wouldn't go everytimes I refresh the page while placing the code on the same page so i did put the button referencing <form method="post" action="sendmail.php"> <div align="center"> <input type="submit" value="send this email"/> </div> </form> so that if i press the button mail would go to student, no luck Quote Link to comment Share on other sites More sharing options...
linux1880 Posted December 17, 2007 Author Share Posted December 17, 2007 Putting that code on the same page also would give the solution but is there any way to stop going mail everytime i open the page or refresh the page ? Thank you. Quote Link to comment 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.