PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 13th, 2012, 05:35 PM
arkingIT arkingIT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 7 arkingIT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 21 sec
Reputation Power: 0
Other - Formatting text emails

Hello Maximum or anyone else that can help me.

I have a form with a text field named "text" and I wrote an application using php. The application emails all registered users the text that the user entered into the "text" field. What I want to do is format the email text so that it has a background color of #dbe5c4, width of 500 pixels. Here is the form:

<form method="post" action="sendemail.php">
Subject of email <br />
<input type="text" id="subject" name="subject" size="60" />
<br />
<br />
Body of email:<br />
<textarea id="text" name="text" rows="8" cols="60"></textarea>
<br />
<br />
<input type="submit" value="submit" name="submit" />
</form>

Here is the php script that sends the email:

if ((!empty($subject))&&(!empty($text))){

$dbc = mysqli_connect('databaseurl', 'username', 'password', 'database')
or die('Error connecting to MySQL server.');

$query = "SELECT * FROM email_list";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');

// $to, $first_name, $last_name are columns in the database

while ($row = mysqli_fetch_array($result)){
$to = $row['email'];
$first_name = $row['first_name'];
$last_name = $row['last_name'];
//$msg is the the variable that holds the message that the user puts in the text
// field. I want to format the message so that it has a background color and
// width size of 500 pixels. I'm a newbie at PHP so please explain in layman
// terms. Write out the code clearly for me please.

$msg = "Dear $first_name $last_name";
$msg .= "\n\n";
$msg .= "$text";

mail($to, $subject, $msg, 'From: ' . $from);
echo 'Email sent to:' . $to . '<br />';
}

Reply With Quote
  #2  
Old November 13th, 2012, 06:36 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,863 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 19 h 44 m 40 sec
Reputation Power: 813
Hi,

you need to wrap your code in [PHP] tags.



Quote:
Originally Posted by arkingIT
Hello Maximum or anyone else that can help me.


Who is Maximum?



Quote:
Originally Posted by arkingIT
I have a form with a text field named "text" and I wrote an application using php. The application emails all registered users the text that the user entered into the "text" field.


What prevents a bad guy from using this to send a spam mail to all your users in every second? What do you even need this for?

You should at least have a time limit and the possibility to "unsubscribe" from this kind of messages. And I hope this is only possible for logged in users?



Quote:
Originally Posted by arkingIT
What I want to do is format the email text so that it has a background color of #dbe5c4, width of 500 pixels.


Then you need an HTML mail. A plaintext mail has no colors or other styles.

But I definitely wouldn't use the mail() function for this. Use a mailer library like PHPMailer (download the "PHP4" version, the "PHP5/6" version is mislabeled and completely outdated).

Reply With Quote
  #3  
Old November 13th, 2012, 06:49 PM
arkingIT arkingIT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 7 arkingIT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 21 sec
Reputation Power: 0
Thank you but I really want to learn PHP and HTML together. I'm sure there's got to be a simple solution and perhaps you don't know the solution but there's got to be someone out there that can instruct a beginning PHP programmer.

Still yet thank you for your attempt to help me. I need to learn to code I'm a newbie and newbies need baby food so that they can graduate to already designed php code. How am I going to know how to decipher the long code that you or anyone else sends me if I don't know what is going on and how to read it in the first place?

I'm sure now that you can see my delima

Reply With Quote
  #4  
Old November 13th, 2012, 06:52 PM
arkingIT arkingIT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 7 arkingIT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 21 sec
Reputation Power: 0
Yak, I'm yaking code

Why am I yakking code?

yak, I need help, please someone help me

Reply With Quote
  #5  
Old November 13th, 2012, 07:15 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,863 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 19 h 44 m 40 sec
Reputation Power: 813
What the hell are you talking about? The library I gave you is the simplest solution you'll ever find, because it frees you from manually setting mail headers in the mail() function. Have you even looked at the page? There are lots of examples you can copy and paste:

http://phpmailer.worxware.com/index.php?pg=examplebmail

If you find calling a method like AddAddress() or Send() too complicated, I don't know what you expect from us. I mean, there's no magical PHP function send_mail_to_all_my_users() that will do all the work for you. Sure, there's also the possibility to fumble with the mail headers if you don't like libraries. But I doubt that you'll find that easier.

If you have concrete questions regarding the library, simply ask them. I'm sure we can help you with that. And of course there are many other libraries if you don't like this one. But they all work more or less the same.

Last edited by Jacques1 : November 13th, 2012 at 07:30 PM.

Reply With Quote
  #6  
Old November 13th, 2012, 08:22 PM
arkingIT arkingIT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 7 arkingIT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 21 sec
Reputation Power: 0
"What the hell are you talking about?" That's not a nice way of relating!

I'll look at the code, ty.

Reply With Quote
  #7  
Old November 13th, 2012, 08:23 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 48 m 54 sec
Reputation Power: 7053
Quote:
Thank you but I really want to learn PHP and HTML together. I'm sure there's got to be a simple solution and perhaps you don't know the solution but there's got to be someone out there that can instruct a beginning PHP programmer.

You can't format an E-Mail without using HTML. A text email can only be sent unformatted.

Formatting text using HTML isn't hard, but if you don't know how to do that you're going to have to learn it first. For example, if you want to send red text in your email you have to use something like:
Code:
<span style="color:red">red text</span>

A basic HTML tutorial is beyond the scope of this forum, but there are many of them online.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #8  
Old November 13th, 2012, 08:42 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,863 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 19 h 44 m 40 sec
Reputation Power: 813
Quote:
Originally Posted by arkingIT
"What the hell are you talking about?" That's not a nice way of relating!


Not even looking at the page and saying that you rather wait for somebody else to give a "simple solution" I might not know isn't very nice either, right?

The thing is: I'll happily answer your questions or look for a different solution if you have specific preferences. But if I link you to a script that was explicitly designed to make sending mails easy and you just ignore it, well, what am I supposed to think about that?

Long story short: If you want to stick with the mail() function, you need to set the mail header as described in the php.net link I gave you. Otherwise you need an external library.

Reply With Quote
  #9  
Old November 13th, 2012, 09:10 PM
arkingIT arkingIT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 7 arkingIT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 21 sec
Reputation Power: 0
I like the idea of red text. How am I suppose to use it in my email message and since $msg is the variable that hold the form info (mail($to, $subject, $msg, 'From: ' . $from); ) I'll need to know how to use red text in that variable. I tried to use the following but it didn't work. The first, third, and forth line works, but I need the second line to work too:

$msg = "Dear $first_name $last_name";
$msg .= '<span style="color:red">Dear $first_name $last_name </span>';
$msg .= "\n\n";
$msg .= "$text";

Reply With Quote
  #10  
Old November 13th, 2012, 09:47 PM
arkingIT arkingIT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 7 arkingIT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 21 sec
Reputation Power: 0
Your telling me that I have to use someone else's code to use color my emails? I've never had problems with using color and I'm an artist by nature and that's why I like to use color in my html emails. I'm perplexed because out of all the years I've worked with Dreamweaver, Photoshop, CSS I thought that I'd never be able to not use my own color using a set standard of syntax for e-mails.

It's just taking me for a surprise that's all. I'm disappointed but what can I expect, I'm new at this stuff.

Reply With Quote
  #11  
Old November 13th, 2012, 10:53 PM
BarryG BarryG is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Location: Sydney Australia
Posts: 131 BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 7 h 51 m 28 sec
Reputation Power: 83
Quote:
Originally Posted by arkingIT
Your telling me that I have to use someone else's code to use color my emails? I've never had problems with using color and I'm an artist by nature and that's why I like to use color in my html emails. I'm perplexed because out of all the years I've worked with Dreamweaver, Photoshop, CSS I thought that I'd never be able to not use my own color using a set standard of syntax for e-mails.

It's just taking me for a surprise that's all. I'm disappointed but what can I expect, I'm new at this stuff.


"Someone else's code" makes your job easier.

Email is plain old text, no formatting, no colour, nothing, just text, unless you build it as html.
If you want to do that by hand, it's not hard, just look up mail() in the php manual. There's an example of how to do html email
http://au1.php.net/manual/en/function.mail.php
Example #4

BUT, you need to know how to build the html, with css, to make your mail look right.

Reply With Quote
  #12  
Old November 14th, 2012, 04:55 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,863 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 19 h 44 m 40 sec
Reputation Power: 813
arkingIT, what are you here for? Do you want to solve your problem and get on? Or do you just want to chat a bit?

If you're here to get help, then, for god's sake, start to read what people are telling you and click on the links you get.

I told you at least twice that you have two options, the mail() function being one of them. I also gave you a link to php.net with an explanation of how to set the headers in the mail() function to send an HTML mail (it's also in BarryG's reply). But you keep complaining about having to use "someone else's code". No, you do not have to use "someone else's code". You can stick to your mail() function if you want to. But then you have to set additional headers (do you want me to write down the link again?).

Again, there are two possibilities to send HTML mails:
  1. via the mail() function, but then you have to set several headers
  2. with an external library, which you obviously don't want to use

Both options require some work on your part. You have to at least copy and paste the examples from the links. Don't expect us to do that for you.

By the way: You should definitely get accustomed to using "someone else's code". If you're unable to choose the right tool for the job and instead keep reinventing the wheel, you won't get very far. Every website that's more than just some pretty HTML relies on external libraries and frameworks.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Other - Formatting text emails

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap