473,513 Members | 2,537 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15925
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
8551
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
3485
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. - Creating training material themselves in many langauges built to order. The main thing I'm thinking about for the company is maybe a sort of content
4
3431
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
1583
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 that doesent use much memory. I know a lot of C++ programmers ,and they tolded me, that C++ templates are real solution for dynamical memory use...
4
1356
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: <orderlist> <order> <header> <ordernum>1313</ordernum> </header> </order>
4
1482
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 the messages are different, the way to handle the message is the same. Hence I'm thinking of using templates to reduce the number of lines in the...
3
1430
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
1958
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, either C# or VB.NET, that I can try. Thank You Very Much,
1
2860
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 stores a $_SESSION variable. After the upload is complete, the server supplies a link that allows the user to view their link codes. Once they click...
3
1482
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() {}; virtual ~CCodec(){};
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7565
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.