Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Web Coding

Reply
 
LinkBack Thread Tools
Old 08-28-09   #1 (permalink)
Case Modder
 
Sullivan's Avatar
 
intel nvidia

Join Date: Feb 2009
Location: Houston, TX
Posts: 1,852

Rep: 105 Sullivan is acknowledged by manySullivan is acknowledged by many
Unique Rep: 93
Trader Rating: 12
Default Needs help with emailer (php)

Okay, so for a weekend project for my web design course we have to design a emailer. I pretty much have it done, I just need to get it to where I can use html in the message.

Heres my work:

PHP Code:
//Made by T.Sullivan
<?php
if (!isset($_POST["send"])) {
// no post data -> display form
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start();
?>
<form method="POST" action="<?=$_SERVER['PHP_SELF'];?>">
To: <input type="text" name="to"><br>

From: <input type="text" name="sender"><br>

Subject: <input type="text" name="subject"><br>

Message:<br>

<textarea name="message" rows="10" cols="60" lines="20"></textarea>

<input type="submit" name="send" value="Send">

</form>
<?
} else {
// found post data .. deal with it
$from=$_POST['sender'];
// send mail
if (mail($_POST['to'], $_POST['subject'],$_POST['message'],"From: $from\n")){
// success
echo "Your mail was sent.";
} else {
// error
echo "Your email was not sent.";
}
}
?>
__________________

System: My First Build
CPU
Q6600 G0 (SLACR) @2.44
Motherboard
Gigabyte EP45-UD3P
Memory
OCZ Reaper HPC Edition 4Gb
Graphics Card
eVGA GTS250
Hard Drive
640Gb Seagate 500Gb Samsung
Sound Card
Integrated Dolby Didgital
Power Supply
Corsair TX850w
Case
Antec 900 Modded
CPU cooling
Tuniq Tower 120 w/ 120mm Fan
GPU cooling
Stock
OS
XP SP3 32Bit - Windows 7 7100 64Bit
Monitor
Hanns-G 28" LCD
Sullivan is offline   Reply With Quote
Old 09-04-09   #2 (permalink)
Programmer
 
Faster_is_better's Avatar
 
amd ati

Join Date: Mar 2007
Posts: 407

Rep: 19 Faster_is_better Unknown
Unique Rep: 18
Trader Rating: 6
Default

I'm not sure if this would be cheating, but.... Contact form Generator here

You can at least use the end code for ideas..

I think you are going to have to put the form entries into variables, and then you can build your message.

example code:

PHP Code:
<?php

$EmailFrom 
Trim(stripslashes($_POST['email']));
$EmailTo "email@e.com";
$Subject "Comments";
$name Trim(stripslashes($_POST['name'])); 
$email Trim(stripslashes($_POST['email'])); 
$comments Trim(stripslashes($_POST['comments'])); 

$Body "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Comments:";
$Body .= "\n";
$Body .= $comments;
$Body .= "\n";


$success mail($EmailTo$Subject$Body"From: <$EmailFrom>");

if (
$success){
  print 
"<meta http-equiv=\"refresh\" content=\"0;URL=thank_you_contact.htm\">";
} else {
  print 
"<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}

?>
hope this helps
__________________
92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this.

System: Black Beast
CPU
AMD Athlon 64 6000+ 3 GHz
Motherboard
M2R32-MVP
Memory
2 x 1GB CORSAIR XMS2
Graphics Card
X1950xtx Crossfire
Hard Drive
2 x WD 160GB SATA, 1 x WD 250GB
Sound Card
X-Fi Platinum
Power Supply
Ultra X-3 800 Watt
Case
Thermaltake Armor Black
CPU cooling
Arctic Freezer Pro 64
GPU cooling
stock
OS
XP Home
Monitor
Samsung 22" 2232BW+ 2ms
Faster_is_better is offline   Reply With Quote
Old 09-05-09   #3 (permalink)
Networking Nut
 
Lyoko's Avatar
 
intel nvidia

Join Date: Aug 2006
Posts: 2,199

Rep: 84 Lyoko is acknowledged by some
Unique Rep: 78
FAQs Submitted: 1
Trader Rating: 3
Default

Just wrote this up. Look at it closely: no variables are saved, no output buffers are used (all in all overhead is reduced) and the code is clean all around. These are attributes you may want to have in your future code

PHP Code:
<?php
if(isset($_POST['send'])) {
  exit((
mail($_POST['to'], $_POST['subject'], $_POST['message'], "From: {$_POST['sender']}") ? 'Your email was sent!' 'Your email was not sent!')); //Exit and spit out a message depending on whether or not the mail function was successful.
} else {
?>
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
    <label for="to">To:</label> <input name="to" id="to" type="text" /><br />
    <label for="from">From:</label> <input name="from" id="from" type="text" /><br />
    <label for="subject">Subject:</label> <input name="subject" id="subject" type="text" /><br />
    <fieldset>
      <legend>Message</legend>
      <textarea name="message" id="message" rows="10" cols="60" lines="20"></textarea><br />
    </fieldset>
    <input type="submit" name="send" />
</form>
<?
}
?>
Though, if you are using this on a production site, make sure to include data validation methods.

Last edited by Lyoko : 09-06-09 at 06:04 PM Reason: Label typos
Lyoko is offline   Reply With Quote
Old 09-05-09   #4 (permalink)
Case Modder
 
Sullivan's Avatar
 
intel nvidia

Join Date: Feb 2009
Location: Houston, TX
Posts: 1,852

Rep: 105 Sullivan is acknowledged by manySullivan is acknowledged by many
Unique Rep: 93
Trader Rating: 12
Default

That looks much nicer, thanks for helping guys.

But yet, no HTML support works...

A friend mentioned maybe trying to add these to the headers:

Quote:
"MIME-Version: 1.0\n" .
"Content-type: text/html; charset=iso-8859-1"
But I did, and I failed, I am completely new to PHP, so maybe you can guide me.
__________________

System: My First Build
CPU
Q6600 G0 (SLACR) @2.44
Motherboard
Gigabyte EP45-UD3P
Memory
OCZ Reaper HPC Edition 4Gb
Graphics Card
eVGA GTS250
Hard Drive
640Gb Seagate 500Gb Samsung
Sound Card
Integrated Dolby Didgital
Power Supply
Corsair TX850w
Case
Antec 900 Modded
CPU cooling
Tuniq Tower 120 w/ 120mm Fan
GPU cooling
Stock
OS
XP SP3 32Bit - Windows 7 7100 64Bit
Monitor
Hanns-G 28" LCD
Sullivan is offline   Reply With Quote
Old 09-06-09   #5 (permalink)
Networking Nut
 
Lyoko's Avatar
 
intel nvidia

Join Date: Aug 2006
Posts: 2,199

Rep: 84 Lyoko is acknowledged by some
Unique Rep: 78
FAQs Submitted: 1
Trader Rating: 3
Default

Quote:
Originally Posted by Sullivan View Post
That looks much nicer, thanks for helping guys.

But yet, no HTML support works...

A friend mentioned maybe trying to add these to the headers:



But I did, and I failed, I am completely new to PHP, so maybe you can guide me.
I'm confused... Are you trying to display this page from your rig?

If so, you need a web server (Nginx, Lighty, Apache [either of the three will work, you only need one]) and PHP installed with the said page in the proper folder so it can be executed by the php interpreter when you access it.

PHP is executed on the server side (not client side/by the browser [like javascript]) so it will not work if you just save the page and try to view it.

Your friend probably thought that you already had your web server and php ready to go, but I am not sure how changing the content encoding and mime version would help the issue at all.

Once you have installed the web server and php, save the code I previously posted to a file (index.php preferrably) and cut/paste it to your server's web root.

Then, go to http://localhost/index.php

and you should be up and running

Last edited by Lyoko : 09-06-09 at 06:22 PM Reason: Tutorial link was too much, just try apache.
Lyoko is offline   Reply With Quote
Old 09-06-09   #6 (permalink)
Case Modder
 
Sullivan's Avatar
 
intel nvidia

Join Date: Feb 2009
Location: Houston, TX
Posts: 1,852

Rep: 105 Sullivan is acknowledged by manySullivan is acknowledged by many
Unique Rep: 93
Trader Rating: 12
Default

No, dude, its being run off a webserver. Online.

Go host your script, and test it out.

What you type is what you see.

If you type:
Quote:
<html>
<body>
<b>test, this is bold text</b>
</body>
</html>
That is what you will see.
__________________

System: My First Build
CPU
Q6600 G0 (SLACR) @2.44
Motherboard
Gigabyte EP45-UD3P
Memory
OCZ Reaper HPC Edition 4Gb
Graphics Card
eVGA GTS250
Hard Drive
640Gb Seagate 500Gb Samsung
Sound Card
Integrated Dolby Didgital
Power Supply
Corsair TX850w
Case
Antec 900 Modded
CPU cooling
Tuniq Tower 120 w/ 120mm Fan
GPU cooling
Stock
OS
XP SP3 32Bit - Windows 7 7100 64Bit
Monitor
Hanns-G 28" LCD
Sullivan is offline   Reply With Quote
Old 09-07-09   #7 (permalink)
Programmer
 
newbie1911's Avatar
 
Join Date: Jul 2008
Posts: 321

Rep: 19 newbie1911 Unknown
Unique Rep: 17
Trader Rating: 0
Default

Quote:
Originally Posted by Sullivan View Post
No, dude, its being run off a webserver. Online.

Go host your script, and test it out.

What you type is what you see.

If you type:


That is what you will see.
Code:
<html>
<head>
    <title>Goodbye World!</title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1257" />
</head>

<body> 
//Made by T.Sullivan
<?php
if (!isset($_POST["send"])) {
// no post data -> display form
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start();
?>
<form method="POST" action="<?=$_SERVER['PHP_SELF'];?>">
To: <input type="text" name="to"><br>

From: <input type="text" name="sender"><br>

Subject: <input type="text" name="subject"><br>

Message:<br>

<textarea name="message" rows="10" cols="60" lines="20"></textarea>

<input type="submit" name="send" value="Send">

</form>
<?
} else {
// found post data .. deal with it
$from=$_POST['sender'];
// send mail
if (mail($_POST['to'], $_POST['subject'],$_POST['message'],"From: $from\n")){
// success
echo "Your mail was sent.";
} else {
// error
echo "Your email was not sent.";
}
}
?>
</body>
</html>
is this what ur asking? also you may need to change the charset
__________________
90% of statistics are made up on the spot. including this one.
newbie1911 is offline   Reply With Quote
Old 09-07-09   #8 (permalink)
Networking Nut
 
Lyoko's Avatar
 
intel nvidia

Join Date: Aug 2006
Posts: 2,199

Rep: 84 Lyoko is acknowledged by some
Unique Rep: 78
FAQs Submitted: 1
Trader Rating: 3
Default

Quote:
Originally Posted by Sullivan View Post
No, dude, its being run off a webserver. Online.

Go host your script, and test it out.

What you type is what you see.

If you type:

...

That is what you will see.
You said you were new to PHP so I assumed you were making a newbie mistake. Obviously, I was mistaken!

I have uploaded the script to my web server and have pm'd you the link; it's working fine.
Lyoko is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 01:04 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.17888 seconds with 8 queries