
06-18-2005, 03:35 PM
|
|
Newbie
|
|
Join Date: May 2005
Location: Gaza, Palestine
Posts: 25
|
|
php: simple code to send HTML email
good day,
this simple code lines will help you sending html email.
of course you can enhance for your need eg. using form, using it in newsletter etc.
but outcoming emails might reported as spam ... so when you test don't forget to check you bulk/junk mail  lol..
PHP Code:
<?
//change this to your email.
$to = "m@maaking.com";
$from = "m2@maaking.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message = <<<EOF
<html>
<body bgcolor="#DCEEFC">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color="red">Thanks Mohammed!</font> <br>
<a href="http://www.maaking.com/">* maaking.com</a>
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>
EOF;
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email@maaking.cXom[/email]";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
|
| Thread Summary |
|
This thread contains 2 different methods of code to send HTML email.
The first simple php script is included in the first post.
PHP Code:
<?
//change this to your email.
$to = "m@maaking.com";
$from = "m2@maaking.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message = <<<EOF
<html>
<body bgcolor="#DCEEFC">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color="red">Thanks Mohammed!</font> <br>
<a href="http://www.maaking.com/">* maaking.com</a>
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>
EOF;
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email@maaking.cXom[/email]";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
The second code uses MIME
PHP Code:
<?
//change this to your email.
$to = "m@maaking.com";
$from = "m2@maaking.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message = "<html>
<body bgcolor=\"#DCEEFC\">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color=\"red\">Thanks Mohammed!</font> <br>
<a href=\"http://www.maaking.com/\">* maaking.com</a>
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>";
//end of message
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: $from\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email@maaking.cXom[/email]";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
For either code, simply update the details to what you need. EXAMPLE: me @ MY domain dot com
Contributors: SoftWareRevue
|
|

06-18-2005, 03:50 PM
|
|
Newbie
|
|
Join Date: May 2005
Location: Gaza, Palestine
Posts: 25
|
|
this one uses MIME.
PHP Code:
<?
//change this to your email.
$to = "m@maaking.com";
$from = "m2@maaking.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message = "<html>
<body bgcolor=\"#DCEEFC\">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color=\"red\">Thanks Mohammed!</font> <br>
<a href=\"http://www.maaking.com/\">* maaking.com</a>
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>";
//end of message
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: $from\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email@maaking.cXom[/email]";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
|

06-22-2005, 10:50 PM
|
|
Aspiring Evangelist
|
|
Join Date: Apr 2002
Location: New Jersey
Posts: 353
|
|
If you are looking for a great php mailer class I would recommend http://phpmailer.sourceforge.net.
I have been using this class for 3 years and love it. It has tons of features, redundant smtp servers, smtp auth, word wrap, multiple tos, ccs, etc.
This class is also works really weel with attachments. I use it to send spreadsheet bandwidth reports based on sql queries.
|

07-05-2005, 10:27 PM
|
|
Newbie
|
|
Join Date: Jul 2005
Location: Minnesota, USA
Posts: 6
|
|
Quote:
Originally posted by Aaton35
If you are looking for a great php mailer class I would recommend http://phpmailer.sourceforge.net.
I have been using this class for 3 years and love it. It has tons of features, redundant smtp servers, smtp auth, word wrap, multiple tos, ccs, etc.
This class is also works really weel with attachments. I use it to send spreadsheet bandwidth reports based on sql queries.
|
Thanks for that link! I checked it out and it looks like I can definitely find a use for this. Thanks again!
|

11-23-2005, 02:49 PM
|
|
Newbie
|
|
Join Date: Nov 2005
Posts: 7
|
|
phpclasses.net is a great resource for all this kind of stuff
hth
craig
|

11-23-2005, 08:55 PM
|
|
WHT Addict
|
|
Join Date: Sep 2004
Location: England UK
Posts: 121
|
|
for more information on php's mail() function you can visit: php sendmail tutorial
|

11-28-2005, 08:08 AM
|
|
Newbie
|
|
Join Date: Nov 2005
Posts: 5
|
|
take a look at PEAR project functionalities - it has everything, that someone can struggle for....
|

11-29-2005, 05:32 AM
|
|
New Member
|
|
Join Date: Nov 2005
Posts: 0
|
|
Great Mohammed
but if i need this email send it to me at specific time ??? what is the change
can i make to do that ?
thanxs
|

01-22-2006, 05:23 PM
|
|
New Member
|
|
Join Date: Jan 2006
Posts: 0
|
|
Sending PHP in the HTML sent via PHP :)
Hey thanks for anyhelp offered.
I am hoping to use this code at the start of this thread to send HTML to users. The email send the HTML but if I do an:
<? echo "$Vars"; ?> in the code the php does not show up?
Is there a way to get dynamic data sent in the HTML via PHP?
thanks so much for your help.
-Ed
|

01-23-2006, 12:10 PM
|
|
Web Hosting Guru
|
|
Join Date: Nov 2005
Posts: 268
|
|
yes ed
In Heredoc or regular strings using $varname or {$varname} will give you the dynamic output you want.
PHP Code:
//Any of these methods will allow inserting of variable values into the variable
$drink = "Coke";
$se = "her";
$heredoc <<< EMAIL
The Customer would like a straw in $se $drink.
EMAIL;
$stringdblquote = "The Customer would like a straw in $se $drink.";
$concatnate = 'The Customer would like a straw in ' . $se . ' ' . $drink;
//unfortunatly without using {} php becomes greedy.
$invalid = "The Customers would like a straw in their $drinks."; //outputs "The Customers would like a straw in their ."
//using {} can force php to evalueate the correct number of letters.
$valid = "The Customers would like a straw in their {$drink}s."; //outputs "The Customers would like a straw in their Cokes."
|

01-23-2006, 03:25 PM
|
|
New Member
|
|
Join Date: Jan 2006
Posts: 0
|
|
A thousand thanks to Korvan
hey Thanks so much Korvan for the advice I was looking for. It really helped me out. I am pretty pumped about sending dynamic data in emails in HTML and php.
thanks!
HUE THEM ANN!
-Ed
|

01-23-2006, 09:39 PM
|
|
New Member
|
|
Join Date: Jan 2006
Posts: 0
|
|
Hey Korvan,
Another question for you. How do I use a for in this html? You will see my example below. Basically I am calling the VARS from a datadase and creating html tables base on the number of results. Then I want to email those VARS in an html format. Any suggestions?
I tried useing $HTML_Data = 'include'DatabaseScript.php'; and then putting $HTML_VAR in the code below in place of the For Loop, but that didn't work either.
thanks for your time. If you have a paypal account I would like to donate something to you to say thanks for your time. Have a great night.
//Any of these methods will allow inserting of variable values into the variable
$drink = "Coke";
$se = "her";
$heredoc <<< EMAIL
<? $TheCount++; for($i=1; $i < $TheCount; $i++) { $HailMary .=$ItemsOrdered[$i][0];$HailMary .=$ItemsOrdered[$i][1];$HailMary .=$ItemsOrdered[$i][2]; $HailMary .=$ItemsOrdered[$i][3]; $HailMary .=$ItemsOrdered[$i][4]; }//$HailMary .= "<br>"; echo "$HailMary"; ?>
EMAIL;
$stringdblquote = "The Customer would like a straw in $se $drink.";
|

01-23-2006, 10:08 PM
|
|
New Member
|
|
Join Date: Jan 2006
Posts: 0
|
|
Ok so I got an include to work with spiting out the html, however it is not getting my Vars from the Database? Any Suggestions? Here is the code:
$MyVars = get_include_contents('MyFile.php');
function get_include_contents($filename) {
if (is_file($filename)) {
import_request_variables ( 'gp' );
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
return false;
}
//begin of HTML message
$message = <<<EOF
$MyVars
EOF;
|

01-24-2006, 04:51 PM
|
|
Web Hosting Guru
|
|
Join Date: Nov 2005
Posts: 268
|
|
I do not know how to fix that unless i know whats query you are running.
So what is your sql query? I could give you an example
Also you cannot put <? ... ?> inside the heredoc and expect php to process that code. It just wont, instead it will output those tags. (or dump them in a var).
PHP Code:
//you only can run database query after the connection to your database is open.
$sql = "SELECT id, name, job FROM example_tbl";
if(!($result = mysql_query($sql)))
{
//error
}
else
{
//grab data from the database
$output = NULL;
//create our welcome or header message
$output .= "Hello Dude, this is an example email!<br />\r\n";
while(($arr = mysql_fetch_assoc($result)))
{
$output .= "Person <b>{$arr['name']}</b> does {$arr['job']}<br />\r\n";
}
//close the output
$output .= "<br />\r\n<br />\r\nHave a nice day!<br />\r\n Mr. Ed";
}
//output now contains what you are emailing. note this is just an example and
//you will need to adjust it to fit your needs.
|

01-24-2006, 06:46 PM
|
|
New Member
|
|
Join Date: Jan 2006
Posts: 0
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|