473,221 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

Using templates to send e-mail in PHP

I'm looking at sending e-mails from PHP based on templates with
expansion of variables, similar to a mail merge. Does anyone know of
existing code for this or can point me in the right direction. I
assume I will need to use regexps but am not yet sure exactly how.

Any advice gratefully recieved,
Geoff
Jul 17 '05 #1
5 15916
Geoff Soper wrote:
I'm looking at sending e-mails from PHP based on templates with
expansion of variables, similar to a mail merge. Does anyone know of
existing code for this or can point me in the right direction. I
assume I will need to use regexps but am not yet sure exactly how.

Any advice gratefully recieved,
Geoff


Hi Geoff,

I would advise you to just roll your own.
First try to send an email (to yourself) with PHP. If it works fine, start
messing with the bodycontent.

If you want to send to a load of people stored in a database, just loop
though the resultset and create a seperate email for everyone in the
resultset.

You can use a template with placeholders.
example:

// databasequery

for (...) {

$db_fullname = $row["fullname"];
$db_email = $row["email"];

$message = "\n";
$message .= "Dear ".$db_fullname.",\n";
$message .= "\n";
$message .= "How do you like our email?\n";
$message .= "\n";
$message .= "Regards,\nGeoff\n";

$subject = "My newsletter.";

mail ($db_email, $subject, $message);

}
Should work.

Regards,
Erwin

Jul 17 '05 #2
Hello Erwin / Geoff,

Erwin Moller wrote:
Geoff Soper wrote:
I'm looking at sending e-mails from PHP based on templates with
expansion of variables, similar to a mail merge. Does anyone know of
existing code for this or can point me in the right direction. I
assume I will need to use regexps but am not yet sure exactly how.
You can use a template with placeholders.


Besides the example of Erwin, you could also use the include
statement to include your mail template, which would be a
normal php file ( HTML with php code embedded ) and use
ob_start and the other ob_* functions to catch the output
of the mail template.

Advantage of this approach is that your templates can
be HTML with some placeholders and you don't have to
play with concatenation of strings containing HTML
with lots of escape sequences a.s.o.

Best regards,

Eric Veltman
Jul 17 '05 #3
Hello,

On 01/26/2004 10:51 AM, Geoff Soper wrote:
I'm looking at sending e-mails from PHP based on templates with
expansion of variables, similar to a mail merge. Does anyone know of
existing code for this or can point me in the right direction. I
assume I will need to use regexps but am not yet sure exactly how.


You may want to look at this class. It comes with an example of sending
personalized mailings to multiple receipients, using Smarty engine to
compose messages based on templates. This is faster than doing regular
expression based replacements of placeholders.

The example shows how to compose personalized HTML messages with
alternative and also personalized text parts that are viewed only on
mail programs that do not support HTML. There are also separate HTML and
text templates for use in this example with Smarty.

http://www.phpclasses.org/mimemessage

--

Regards,
Manuel Lemos

Free ready to use OOP components written in PHP
http://www.phpclasses.org/

MetaL - XML based meta-programming language
http://www.meta-language.net/

Jul 17 '05 #4
ge*****************@alphaworks.co.uk (Geoff Soper) wrote in message news:<8e**************************@posting.google. com>...
I'm looking at sending e-mails from PHP based on templates with
expansion of variables, similar to a mail merge. Does anyone know of
existing code for this or can point me in the right direction. I
assume I will need to use regexps but am not yet sure exactly how.

Any advice gratefully recieved,


My taste...

$from_email = 'fetched from DB or so';
$to_email = 'fetched from DB or so';
$name = 'fetched from DB or so';
//send via mail template...
include('./includes/mailtemplates/send_welcome_msg.inc.php');
<?php
//send_welcome_msg.inc.php
//mail template file.... May use some other codes to edit this
template file
$subject = 'xxxxxxx';
$message = <<<EOT
Hiiii $name,

xxxxx

Webmaster
EOT;
//send email...
mail($to_email, $subject, $message,
"From: Webmaster <$from_email>\r\n" .
"Reply-To: $from_email\r\n" .
"X-Mailer: PHP/" . phpversion()
);
?>
--
"I don't believe in the God who doesn't give me food, but shows me
heaven!" -- Swami Vivekanandha
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5
R. Rajesh Jeba Anbiah wrote:

<?php
//send_welcome_msg.inc.php
//mail template file.... May use some other codes to edit this
template file
$subject = 'xxxxxxx';
$message = <<<EOT
Hiiii $name,

xxxxx

Webmaster
EOT;
//send email...


(Off topic)

Thanks Rajesh,

You just did me huge favor. :-)
I was really missing my Perl here-documents, and for some silly reason I
didn't expect to find them in PHP, but they are just there!
You just showed me. :-)
Thanks.

Regards,
Erwin Moller

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Sebastian Faust | last post by:
Hi, is a construction like the following possible: template<class view_model> class template_clase { protected: template_clase() {} virtual ~template_clase() {}
12
by: Simon Harvey | last post by:
Whato chaps, I work (or am hoping to work! :) for a company that specialises in the following: - Localisation of media - including software, manuals, literature and training material. -...
4
by: Pat Turner | last post by:
Hi, I have some XML like this: <family> <person name="bob"> <father ref="../../person" /> </person> <person name="charlie"> <child ref="../../person" />
2
by: Bore Biko | last post by:
Dear, I am an ordinary C programmer and I am most interesed about dynamical data structuring and programming, I don't like to use matricess and rows, I like to program with practical programs...
4
by: n.phelge | last post by:
I'm trying to validate XML which doesn't include a namespace, so I've written a schema and I'm attempting to add a namespace to the original XML using XSLT. The original XML looks like this: ...
4
by: qning88 | last post by:
I would like to find out how I can effectively make use of templates in theexample below. In Class A, I have 3 overloaded member functions "send" for handling the different messages. Although...
3
by: Homer | last post by:
Hi All, I have following XML File: <Header></Header> <Category></Category> <Item1></Item1> <Item2></Item2> <Category></Category> <Item3></Item3>
2
by: shapper | last post by:
Hello, I am for days trying to apply a XSL transformation to a XML file and display the result in a the browser. I am using Asp.Net 2.0. Please, could someone post just a simple code example,...
1
by: bsprogs | last post by:
I am currnetly programming a file hosting website in PHP and I am slowly integrating AJAX into the website. Here is my problem: The user uploads the file. The server processes the file and...
3
by: tech | last post by:
Hi, i have the following design issue. In our app we use different codecs to encode/decode packets of data I have defined a base codec class as follows class CCodec { public: CCodec() {};...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.