Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i am trying to send email from php i have one php file with all values & other php template file.

(both files are on same server)

i am using file_get_contents to get contents of php template file for example

   $url="emil_form.php";
   $a="uname";
  if(($Content = file_get_contents($url. "?uname=".$a)) === false) {
   $Content = "";
    }

   ...... EMAIL Sending Code ..........

and here is code for emil_form.php (email template file)

    Your Name is : <?php $_GET['uname']; ?>

so once i got data in $Content i can send it by email. but i am getting error unable to open file....

what i want is pass data from original php file to template php file and what will be output of template stored in variable so i can send it by email.

how can do this ?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
373 views
Welcome To Ask or Share your Answers For Others

1 Answer

The real problem would be that you try to read a local file with a http query string behind it. The file system don't understand this and looks for a file called "emil_form.php?uname=uname". $_GET / $_POST / etc only works over a http connection.

Try to put a placeholder like "%%NAME%%" in your template and replace this after reading the template.

<?php
$url = "emil_form.php";
$a   = "uname";
if(($Content = file_get_contents($url)) === false) {
   $Content = "";
}
$Content = str_replace('%%NAME%%', $a, $Content); 
// sending mail....

Template will look like this:

Your Name is: %%NAME%%

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...