hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Web Hosting Talk Tutorials : Programming Tutorials : php: simple code to send HTML email
Reply

Forum Jump

php: simple code to send HTML email

Reply Post New Thread In Programming Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 06-18-2005, 03:35 PM
making making is offline
Newbie
 
Join Date: May 2005
Location: Gaza, Palestine
Posts: 25
Arrow

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....!";
?>

__________________
the easy can be hard.
Mohammed Ahmed - ME. Palestine
http://www.maaking.com
Email/MSN: m@maaking.com


Thread Summary
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

Share This Summary:

Sponsored Links
  #2  
Old 06-18-2005, 03:50 PM
making making is offline
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....!";
?>

__________________
the easy can be hard.
Mohammed Ahmed - ME. Palestine
http://www.maaking.com
Email/MSN: m@maaking.com

  #3  
Old 06-22-2005, 10:50 PM
SolarVPS SolarVPS is offline
Aspiring Evangelist
 
Join Date: Apr 2002
Location: New Jersey
Posts: 354
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.

__________________
Solar VPS The Best Price to Performance Ratio In Cloud and VPS Hosting
Ross Brouse, President & COO e: management@solarvps.com p: (973)572-1070
The SolarSystem - On Demand VM Creation, Uptime Monitoring, DNS Control and more.
Speed Test: speed.fortressitx.com

Sponsored Links
  #4  
Old 07-05-2005, 10:27 PM
mike.fro mike.fro is offline
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!

  #5  
Old 11-23-2005, 02:49 PM
craigymcfly craigymcfly is offline
Newbie
 
Join Date: Nov 2005
Posts: 7
phpclasses.net is a great resource for all this kind of stuff

hth

craig

  #6  
Old 11-23-2005, 08:55 PM
dotcomguy01 dotcomguy01 is offline
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

__________________
Read Tabloids - Warning Experimental.

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

  #8  
Old 11-29-2005, 05:32 AM
ak25 ak25 is offline
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

  #9  
Old 01-22-2006, 05:23 PM
Mr Ed Mr Ed is offline
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

  #10  
Old 01-23-2006, 12:10 PM
Korvan Korvan is offline
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." 

  #11  
Old 01-23-2006, 03:25 PM
Mr Ed Mr Ed is offline
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

  #12  
Old 01-23-2006, 09:39 PM
Mr Ed Mr Ed is offline
New Member
 
Join Date: Jan 2006
Posts: 0
One More Question

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.";

  #13  
Old 01-23-2006, 10:08 PM
Mr Ed Mr Ed is offline
New Member
 
Join Date: Jan 2006
Posts: 0
working... kind of.

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;

  #14  
Old 01-24-2006, 04:51 PM
Korvan Korvan is offline
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. 

  #15  
Old 01-24-2006, 06:46 PM
Mr Ed Mr Ed is offline
New Member
 
Join Date: Jan 2006
Posts: 0
Post 4

See example below:

Reply

Related posts from TheWhir.com
Title Type Date Posted
Web Hosting Sales and Promos Roundup - September 12, 2014 Web Hosting News 2014-09-12 15:55:25
Open-Xchange Launches Tool to Encrypt Online Communications Web Hosting News 2014-09-03 10:43:43
DIY Website Builder Wix.com Launches Integrated Email Newsletter Tool Web Hosting News 2014-07-10 11:51:24
Web Hosting Sales and Promos Roundup - April 4, 2014 Web Hosting News 2014-05-23 15:42:22
Rackspace Integrates Mailgun into Cloud Control Panel Web Hosting News 2013-05-23 14:55:51


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?