Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Parsing a variable with variables in it

the mail() function

Moderators: macek, egami, gesf

Parsing a variable with variables in it

Postby LANcaster » Wed Feb 19, 2003 12:22 pm

Hi, I was wondering if anyone could help me with this.
I have a mail command as follows:
Code: Select all
<?
mail("$to_email","$subject","$content","From: $from_address");
?>

I need to be able to read the variable '$content' in from a database. '$content' will read something like this:
"Hi $fname,
Your account is as follows:
Username: $username
Password: $password".
So I need PHP to parse '$content' and fill in the variables within it ($fname, $username, $password), however when I run the script I get the following email:

From: address@domain.com
Subject: Subject
Content: Hi $fname,
Your account is as follows:
Username: $username
Password: $password

Thanks in advance.
LANcaster
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Feb 19, 2003 9:15 am

Postby Oleg Butuzov » Wed Feb 19, 2003 11:01 pm

mail with headers...


Code: Select all
$mymail="uadude@hotmail.com";
$subj="Hello, dude!";
$usermessage="Best regards. chao.";

$headers .= "MIME-Version: 1.0\r\n";
 $headers .= "Content-type: text/html; charset=windows-1251\r\n";
 $headers .= "From: Pejone <pejone@ukr.net>\r\n";
 $headers .= "X-Priority: 1\r\n";
 $headers .= "X-MSMail-Priority: High\r\n";
 $headers .= "X-Mailer: Pejone Feedback Form Mailer aka PFFM v1.0.2 special for alesh.ru\r\n";
 
mail($mymail, $subj, $usermessage, $headers);
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby LANcaster » Thu Feb 20, 2003 6:11 am

Hi Pejone,
Thanks for your help, but I think you may has missunderstood what it is I wish to accomplish. I need to use a variable which I have pulled from a database earlier in the script that contains variables which I need PHP to then parse before sending the email. I need this for a program I am writing in PHP which sends out emails and the email 'templates' need to be easily modifyable.
Thanks again.
LANcaster
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Feb 19, 2003 9:15 am

Postby Oleg Butuzov » Thu Feb 20, 2003 6:23 am

Use fast tempelates for making $content =)
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby LANcaster » Thu Feb 20, 2003 11:39 am

Thanks again for your help Pejone, I really appreciate it.
I will have a good look at fast templates later this evening, but just out of interest can you think of any other way of doing this?
LANcaster
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Feb 19, 2003 9:15 am

Postby Oleg Butuzov » Thu Feb 20, 2003 11:43 pm

I don like Fasttempelates, so i use functions

for exemple

Code: Select all
fucntion message_to_sent($Name, $Password, $email, $mymail)
{
$content="Hello $Name
Your login : $Name
Your pass: $Password

Bla-bla-bla...
Bye.
";

mail("$Name <$email>", "Subject", $content ,"From:  $mymail");
}
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Redcircle » Fri Feb 21, 2003 1:26 am

I've never looked at fast templates befor but here is what I would do.
Code: Select all
<?php
$content = "From: address@domain.com
Subject: Subject
Content: Hi [fname],
Your account is as follows:
Username: [username]
Password: [password]";

$content = str_replace('[fname]',$fname,$content);
$content = str_replace('[username]',$username,$content);
$content = str_replace('[password]',$password,$content);
?>




User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby LANcaster » Sat Feb 22, 2003 4:20 pm

Thanks Redcircle, what you suggested works perfectly, I really appreciate your help. :D
LANcaster
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Feb 19, 2003 9:15 am


Return to PHP coding => Mail

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.