Solved

PHP e-mail

Posted on 2004-08-27
31
244 Views
Last Modified: 2012-08-14
I'm building e-mail forms and my host does not allow me to have e-mails go to the right places. I host through Yahoo, and they say I need to use PHP.

I got the following PHP script, but I don't know where to put it in my HTML code. I'm using FrontPage 2003. Where do I put it? I've also got CSS in these pages.


<?php
$to_address = "youraddress@domain.com";
$subject = "your subject";
$message = $_POST['name']."\n".$_POST['email']."\n".$_POST['message'];
mail($toaddress,$subject,$message);
?>



Bob
0
Comment
Question by:weikelbob
  • 11
  • 10
  • 6
  • +2
31 Comments
 
LVL 32

Expert Comment

by:ldbkutty
ID: 11919075
For step-by-step PHP *simple* E-mail example learning :
http://www.buildwebsite4u.com/advanced/php.shtml

>> I got the following PHP script, but I don't know where to put it in my HTML code
I suppose you mean HTML Codes inside a PHP page. If you could show us your HTML Form, i might be able to help.
0
 
LVL 33

Expert Comment

by:humeniuk
ID: 11919183
Here's an easy way to do it using PHP:

Add the following line to your PHP script . . .
 
header("Location:newpage.html");

. . . and replace newpage.html with whatever page you want the user to go to once they have clicked submit and sent the email message.  So, your PHP script is going to look something like this:

<?php

$to_address = "youraddress@domain.com";
$subject = "your subject";
$message = $_POST['name']."\n".$_POST['email']."\n".$_POST['message'];

mail($to_address,$subject,$message);

header("Location:newpage.html");

?>

[note:  I changed 'mail($toaddress,$subject,$message);' to 'mail($to_address,$subject,$message);' so that your mail command would match your $to_address variable]

Then, save that script as something like 'send_mail.php' and upload it to the same directory as your html page with the email form that will be submitted.  Make sure the form then directs to your send_mail.php page:

<form action="send_mail.php" method="post" name="send_mail" id="send_mail">


I hope this helps.  If you need more detailed config. & scripting info, see http://www.experts-exchange.com/Web/Hosting/Q_21106831.html.
0
 
LVL 7

Author Comment

by:weikelbob
ID: 11919378
OK, I hit subit on my form and I get a "cannot be found" error

Please help me out. Here's my code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title></title>
<style type="text/css">

body
{
     margin:0;
     padding:0;
     font:13px arial, verdana, sans-serif;
}

#container
{
     min-width: 700px;
     max-width: 1200px;
     width: expression((this.parentNode.clientWidth > 1200)?1200+"px":(this.parentNode.clientWidth <= 700 + 0)?700+"px":"auto")
}


#header
{
       background:#cccccc;
     text-align:center;
     /* no width needed */
     height:190px;

}

#header img
{
     margin:0 auto;
     display:block;
}


#leftcol
{
     float:left;
     width:29%;
}

#centercol
{
     float:left;
     width:40%;
     text-align:center;
}

#rightcol
{
     float:left;
     width:29%;
}

.spacer
{
     padding:10px 20px;
}

#leftcol p, #rightcol p
{
     text-align:justify;
}

img
{
     border:none;
}

a:link, a:visited, a:hover, a:active
{
     text-decoration:none;
}

</style>
</head>

<body>

<?php

$to_address = "nweikel@aol.com";
$subject = "From Grandma's Page";
$message = $_POST['name']."\n".$_POST['email']."\n".$_POST['message'];

mail($to_address,$subject,$message);

header("Location:www.b-transfers.com/helen");

?>

<div id="container">

<div id="header" style="height: 190px">
     <map name="FPMap0">
            <area href="index.html" shape="rect" coords="430, 172, 487, 189">
            <area href="more.html" shape="rect" coords="502, 174, 639, 189">
            <area href="contact.html" shape="rect" coords="653, 174, 733, 189">
            </map>
     <img border="0" src="header.jpg" width="750" height="190" usemap="#FPMap0"></div>


<div id="leftcol" style="clear:left; width: 20%; height: 283px">
     <div class="spacer">
            <p style="text-align: right; margin-top: -1px; margin-bottom: -1px">&nbsp;<p style="text-align: right; margin-top: -1px; margin-bottom: -1px">&nbsp;</div>
</div>

<div id="centercol" style="width: 58%; height: 195px">
     <div class="spacer">
            <form action="send_mail.php" method="post" name="send_mail" id="send_mail">                        
                  <p style="text-align: left">&nbsp;</p>
                  <p style="text-align: left">Your Name:&nbsp;
                  <input type="text" name="T1" size="29"></p>
                  <p style="text-align: left">Your e-mail:&nbsp;
                  <input type="text" name="T2" size="29"></p>
                  <p style="text-align: left"><span style="vertical-align: top">
                  <font face="Arial">Comments: </font></span>&nbsp;<textarea rows="7" name="S1" cols="41"></textarea></p>
                  <p style="text-align: left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input type="submit" value="Submit" name="B1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input type="reset" value="Reset" name="B2"></p>
            </form>
                  <p>&nbsp;<p>&nbsp;</div>
</div>

<div id="rightcol" style="width: 20%; height: 245px">
     <div class="spacer">
     <div>
            <p style="margin-top: -1px; margin-bottom: -1px">&nbsp;</p>
            </div>
            <div>
                  &nbsp;</div>
            <p>&nbsp;</div>
</div>



<div id="footer" style="width: 100%; height: 50px">
     &nbsp;</div>


</body>
</html>
0
 
LVL 33

Expert Comment

by:humeniuk
ID: 11919419
The problem is that the two pages are combined into one.  The PHP code below should be a page to itself, you can type that exactly as is into your html editor or text editor and save it as a file unto itself named 'send_mail.php'.  Your form action basically says, on submit, go to the send_mail.php file.  The PHP code in this file will send the email and then redirect to the location specified, ie. www.b-transfers.com/helen.  A couple of things to note - if you want to use the whole URL, you need to use 'http://www.b-transfers.com/helen'.  If the page you are redirecting to is in the same directory, you can just use the html page name (ie. 'helen.html').

<?php

$to_address = "nweikel@aol.com";
$subject = "From Grandma's Page";
$message = $_POST['name']."\n".$_POST['email']."\n".$_POST['message'];

mail($to_address, $subject, $message);

header("Location:www.b-transfers.com/helen");

?>


So, two pages:

(1) send-me-email.html - (can be called anything) the web page with the form on it
(2) send_mail.php - (matches your form action) the PHP script that will send the mail and redirect


I hope this helps.
0
 
LVL 9

Expert Comment

by:techtonik
ID: 11919789
PHP script should not be neccessary in separate file. Changing
          <form action="send_mail.php" method="post" name="send_mail" id="send_mail">                
to
          <form method="post" name="send_mail" id="send_mail">                
will also work, but first you need to correct you form, so $_POST array will contain needed fields like so:
...
               <p style="text-align: left">Your Name:&nbsp;
               <input type="text" name="name" size="29"></p>
               <p style="text-align: left">Your e-mail:&nbsp;
               <input type="text" name="email" size="29"></p>
               <p style="text-align: left"><span style="vertical-align: top">
               <font face="Arial">Comments: </font></span>&nbsp;<textarea rows="7" name="message" cols="41"></textarea></p>
               <p style="text-align: left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="submit" value="Submit" name="B1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="reset" value="Reset" name="B2"></p>
...

I've changed values of  name= attribute in form fields.
0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 11920557
If you got 'page not found', then it means:

>> header("Location:www.b-transfers.com/helen");

the above page is not a correct file. Check whether the file really exists (btw, you didn't even gave .php ?)


and as a rule of thumb, header() should occur before any HTML tags are passed. There should not be even a single blank space before <? or <?php
So, put the following at the top of your PHP and remove if from the middle.

<?php

if(isset($_POST['B1']) {
      
 $to_address = "nweikel@aol.com";
 $subject = "From Grandma's Page";
 $message = $_POST['name']."\n".$_POST['email']."\n".$_POST['message'];

 mail($to_address,$subject,$message);

 header("Location:www.b-transfers.com/helen");

}

?>

//  Then your <html> ..... starts from here.
0
 
LVL 33

Expert Comment

by:humeniuk
ID: 11921118
Right, those versions will work ask well.  I prefer it the other way because it's easier for me to keep track of what is where and I can use the script with multiple forms if I want to with variables for the $to_address & $subject if I want to.  It's a matter of what best suits your taste and what other features you might want to add.
0
 
LVL 7

Author Comment

by:weikelbob
ID: 11923078
Almost got it:

When I fill out my e-mail form on my Grandmother's (Helen) page, it sends an e-mail to Nancy and the title is webmaster@b-transfers.com.

However, the e-mail is blank when I open it up.

Does it have to have the title: webmaster@b-transfers.com?
Here's the code:
Here's the entire file of send_mail.php

<?php
$to_address = "nweikel@aol.com";
$subject = "From Grandma's Page";
$message = $_POST['name']."\n".$_POST['email']."\n".$_POST['message'];
mail($to_address,$subject,$message);
header("Location:http://www.b-transfers.com/helen");

here's http://www.b-transfers.com/helen:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title></title>
<style type="text/css">

body
{
     margin:0;
     padding:0;
     font:13px arial, verdana, sans-serif;
}

#container
{
     min-width: 700px;
     max-width: 1200px;
     width: expression((this.parentNode.clientWidth > 1200)?1200+"px":(this.parentNode.clientWidth <= 700 + 0)?700+"px":"auto")
}


#header
{
       background:#cccccc;
     text-align:center;
     /* no width needed */
     height:190px;

}

#header img
{
     margin:0 auto;
     display:block;
}


#leftcol
{
     float:left;
     width:29%;
}

#centercol
{
     float:left;
     width:40%;
     text-align:center;
}

#rightcol
{
     float:left;
     width:29%;
}

.spacer
{
     padding:10px 20px;
}

#leftcol p, #rightcol p
{
     text-align:justify;
}

img
{
     border:none;
}

a:link, a:visited, a:hover, a:active
{
     text-decoration:none;
}

</style>
</head>

<body>
<div id="container">

<div id="header" style="height: 190px">
     <map name="FPMap0">
            <area href="index.html" shape="rect" coords="430, 172, 487, 189">
            <area href="more.html" shape="rect" coords="502, 174, 639, 189">
            <area href="contact.html" shape="rect" coords="653, 174, 733, 189">
            </map>
     <img border="0" src="header.jpg" width="750" height="190" usemap="#FPMap0"></div>


<div id="leftcol" style="clear:left; width: 20%; height: 283px">
     <div class="spacer">
            <p style="text-align: right; margin-top: -1px; margin-bottom: -1px">&nbsp;<p style="text-align: right; margin-top: -1px; margin-bottom: -1px">&nbsp;</div>
</div>

<div id="centercol" style="width: 58%; height: 195px">
     <div class="spacer">
            <form action="send_mail.php" method="POST" name="send_mail" id="send_mail">                        
                  <p style="text-align: left">&nbsp;</p>
                  <p style="text-align: left">Your Name:&nbsp;
                  <input type="text" name="T1" size="29"></p>
                  <p style="text-align: left">Your e-mail:&nbsp;
                  <input type="text" name="T2" size="29"></p>
                  <p style="text-align: left"><span style="vertical-align: top">
                  <font face="Arial">Comments: </font></span>&nbsp;<textarea rows="7" name="S1" cols="41"></textarea></p>
                  <p style="text-align: left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input type="submit" value="Submit" name="B1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input type="reset" value="Reset" name="B2"></p>
            </form>
                  <p>&nbsp;<p>&nbsp;</div>
</div>

<div id="rightcol" style="width: 20%; height: 245px">
     <div class="spacer">
     <div>
            <p style="margin-top: -1px; margin-bottom: -1px">&nbsp;</p>
            </div>
            <div>
                  &nbsp;</div>
            <p>&nbsp;</div>
</div>



<div id="footer" style="width: 100%; height: 50px">
     &nbsp;</div>


</body>
</html>
0
 
LVL 33

Accepted Solution

by:
humeniuk earned 250 total points
ID: 11923329
The field names in your form have to correspond with the variables in your PHP script.  For example, the " $_POST['name'] " reference in your PHP script basically means 'the contents of the field from the submitted form called name'.  So, the 'Your Name:' field must be called 'name'.

Therefore, the form in your html page should be this:

          <form action="send_mail.php" method="POST" name="send_mail" id="send_mail">                    
               <p style="text-align: left">&nbsp;</p>
               <p style="text-align: left">Your Name:&nbsp;
               <input type="text" name="name" size="29"></p>
               <p style="text-align: left">Your e-mail:&nbsp;
               <input type="text" name="email" size="29"></p>
               <p style="text-align: left"><span style="vertical-align: top">
               <font face="Arial">Comments: </font></span>&nbsp;<textarea rows="7" name="message" cols="41"></textarea></p>
               <p style="text-align: left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="submit" value="Submit" name="B1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="reset" value="Reset" name="B2"></p>
          </form>
0
 
LVL 7

Author Comment

by:weikelbob
ID: 11923649
There is still nothing inside the body of my sent e-mail.

Thanks you guys,

Here's the php file:

<?php
$to_address = "nweikel@aol.com";
$subject = "From Grandma's Page";
$message = $_POST['name']."\n".$_POST['email']."\n".$_POST['message'];
mail($to_address,$subject,$message);
header("Location:http://www.b-transfers.com/helen/contact.html");
?>

Here's the form:

<form action="send_mail.php" method="POST" name="send_mail" id="send_mail">                        
                  <p style="text-align: left">&nbsp;</p>
                  <p style="text-align: left">name:&nbsp;
                  <input type="text" name="T1" size="29"></p>
                  <p style="text-align: left">email:&nbsp;
                  <input type="text" name="T2" size="29"></p>
                  <p style="text-align: left"><span style="vertical-align: top">
                  <font face="Arial">message</font></span>&nbsp;<textarea rows="7" name="S1" cols="41"></textarea></p>
                  <p style="text-align: left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input type="submit" value="Submit" name="B1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input type="reset" value="Reset" name="B2"></p>
            </form>
0
 
LVL 33

Expert Comment

by:humeniuk
ID: 11923680
You've changed the wrong part of the form.  The text can still say 'Your Name:' but the form field has to be named 'name' not 'T1', the 'Your e-mail:' field has to be named 'email', not 'T2' and the 'Comments:' field has to be named 'message', not 'S1'.  Look at the example below and compare it line by line with your example.  I've put * in front of the rows that have to be changed.

          <form action="send_mail.php" method="POST" name="send_mail" id="send_mail">                    
               <p style="text-align: left">&nbsp;</p>
               <p style="text-align: left">Your Name:&nbsp;
*              <input type="text" name="name" size="29"></p>
               <p style="text-align: left">Your e-mail:&nbsp;
*               <input type="text" name="email" size="29"></p>
               <p style="text-align: left"><span style="vertical-align: top">
*               <font face="Arial">Comments: </font></span>&nbsp;<textarea rows="7" name="message" cols="41"></textarea></p>
               <p style="text-align: left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="submit" value="Submit" name="B1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="reset" value="Reset" name="B2"></p>
          </form>
0
 
LVL 1

Expert Comment

by:magicMush
ID: 11930002
try to use the below code instead of your php code which will enable receiver to be able to reply to message by using email clints reply to button
instead of retyping the email address it will also show the receiver who the message is from by using senders email address
instead of using webmaster@b-transfers.com it will also use their name if the email address is stored in their address book(supported by AOL,
hotmail,yahoo and many more).this code will also enable you to embed html code into your emails. e.g you will be able to add html tags into your message
see how I have replaced your /n breaks with <br> at 3rd line ($message) you will be able to add images etc into your emails as long as you dont break
the string literals meaning you wont be able to use "  quotes in your emails unless you escape them by adding \ before it.
instead of using " you willl be using \"

<?php
  $to_address = "nweikel@aol.com";
  $subject = "From Grandma's Page";
  $message = $_POST['name']."<br>".$_POST['email']."<br>".$_POST['message']."<br>";
  $from = $_POST['name']."<".$_POST['email'].">";
  $rp    = $_POST['email'];
  $org    = 'Grandma's Page.';
  $mailer = 'MKSR-Postimies';

  $head  = '';
  $head  .= "Content-Type: text/html \r\n";
  $head  .= "Date: ". date('r'). " \r\n";
  $head  .= "Return-Path: $rp \r\n";
  $head  .= "From: $from \r\n";
  $head  .= "Sender: $from \r\n";
  $head  .= "Reply-To: $from \r\n";
  $head  .= "Organization: $org \r\n";
  $head  .= "X-Sender: $from \r\n";
  $head  .= "X-Priority: 3 \r\n";
  $head  .= "X-Mailer: $mailer \r\n";

  $body= str_replace("\r\n", "\n", $message);
  $body = str_replace("\n", "\r\n", $message);

  mail($to, $subject, $body, $head);
  header("Location:http://www.b-transfers.com/helen/contact.html");

?>
0
 
LVL 33

Expert Comment

by:humeniuk
ID: 11931672
Right, there's lots you can do with the PHP mail function as magicMush points out.  Either way, though, you have to make your form variables match your script variables.
0
 
LVL 7

Author Comment

by:weikelbob
ID: 11931879
Thank you Magic Mush

Does this script bring up a dialog box saying that the mail has been sent?

If not, how do I do that?
0
 
LVL 1

Expert Comment

by:magicMush
ID: 11931945
No it will not do that.

to do that you gonna have to add some more code and most probably separate the files. but however you donot have to do that. you can do it dynamically.

First of all do you use two separate files (Have you separated your mailing client.)
if you have
are your both files a .php file

0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Assisted Solution

by:magicMush
magicMush earned 250 total points
ID: 11932220
assuming you have separated the files
you can write the results (Whether mail been sent or not) to the page instead of a dialog box then redirect the page after 5 seconds
I think this will be good enough and you can write your addtional html code in between the of and else tags

<?php
  $to_address = "nweikel@aol.com";
  $subject = "From Grandma's Page";
  $message = $_POST['name']."<br>".$_POST['email']."<br>".$_POST['message']."<br>";
  $from = $_POST['name']."<".$_POST['email'].">";
  $rp    = $_POST['email'];
  $org    = 'Grandma's Page.';
  $mailer = 'MKSR-Postimies';

  $head  = '';
  $head  .= "Content-Type: text/html \r\n";
  $head  .= "Date: ". date('r'). " \r\n";
  $head  .= "Return-Path: $rp \r\n";
  $head  .= "From: $from \r\n";
  $head  .= "Sender: $from \r\n";
  $head  .= "Reply-To: $from \r\n";
  $head  .= "Organization: $org \r\n";
  $head  .= "X-Sender: $from \r\n";
  $head  .= "X-Priority: 3 \r\n";
  $head  .= "X-Mailer: $mailer \r\n";

  $body= str_replace("\r\n", "\n", $message);
  $body = str_replace("\n", "\r\n", $message);

if( mail($to, $subject, $body, $head))
{
?>
<!--write your additional code here to make the page look nicer such as title,some images more user friendly stuff-->
<h3>Mail has been sent Successfully</h3>
<p>You will be redirected in 5 seconds <br> alternatively <a href="http://www.b-transfers.com/helen/contact.html">click here</a></p>
<meta http-equiv="REFRESH" content="5;url=http://www.b-transfers.com/helen/contact.html")">
<?php
}
else{
?>
<!--AND HERE write your additional code here to make the page look nicer-->
<h3>Error: Mail cannot be sent plese contact webmaster/techinal department</h3>
<p>You will be redirected in 5 seconds <br> alternatively <a href="http://www.b-transfers.com/helen/contact.html">click here</a></p>
<meta http-equiv="REFRESH" content="5;url=http://www.b-transfers.com/helen/contact.html")">
<?php
}
?>
0
 
LVL 7

Author Comment

by:weikelbob
ID: 11932528
What do you mean by separate files?

Do you mean my original contact page with the form? Should I change that to a .php file?

here's my form, and my 1 php file

<form action="send_mail.php" method="POST" name="send_mail" id="send_mail">                    
               <p style="text-align: left">&nbsp;</p>
               <p style="text-align: left">Your Name:&nbsp;
               <input type="text" name="name" size="29"></p>
               <p style="text-align: left">Your e-mail:&nbsp;
                <input type="text" name="email" size="29"></p>
               <p style="text-align: left"><span style="vertical-align: top">
                <font face="Arial">Comments: </font></span>&nbsp;<textarea rows="7" name="message" cols="41"></textarea></p>
               <p style="text-align: left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="submit" value="Submit" name="B1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="reset" value="Reset" name="B2"></p>
          </form>


PHP FILE:

<?php
  $to_address = "weikelbob@aol.com";
  $subject = "From Grandma's Page";
  $message = $_POST['name']."<br>".$_POST['email']."<br>".$_POST['message']."<br>";
  $from = $_POST['name']."<".$_POST['email'].">";
  $rp    = $_POST['email'];
  $org    = 'Grandma's Page.';
  $mailer = 'MKSR-Postimies';

  $head  = '';
  $head  .= "Content-Type: text/html \r\n";
  $head  .= "Date: ". date('r'). " \r\n";
  $head  .= "Return-Path: $rp \r\n";
  $head  .= "From: $from \r\n";
  $head  .= "Sender: $from \r\n";
  $head  .= "Reply-To: $from \r\n";
  $head  .= "Organization: $org \r\n";
  $head  .= "X-Sender: $from \r\n";
  $head  .= "X-Priority: 3 \r\n";
  $head  .= "X-Mailer: $mailer \r\n";

  $body= str_replace("\r\n", "\n", $message);
  $body = str_replace("\n", "\r\n", $message);

if( mail($to, $subject, $body, $head))
{
?>
<!--write your additional code here to make the page look nicer such as title,some images more user

friendly stuff-->
<h3>Mail has been sent Successfully</h3>
<p>You will be redirected in 5 seconds <br> alternatively <a href="http://www.b-transfers.com/helen

/contact.html">click here</a></p>
<meta http-equiv="REFRESH" content="5;url=http://www.b-transfers.com/helen/contact.html")">
<?php
}
else{
?>
<!--AND HERE write your additional code here to make the page look nicer-->
<h3>Error: Mail cannot be sent plese contact webmaster/techinal department</h3>
<p>You will be redirected in 5 seconds <br> alternatively <a href="http://www.b-transfers.com/helen

/contact.html">click here</a></p>
<meta http-equiv="REFRESH" content="5;url=http://www.b-transfers.com/helen/contact.html")">
<?php
}
?>

0
 
LVL 33

Expert Comment

by:humeniuk
ID: 11932634
If you have PHP script on a page, you should make it a .php page so that the web server knows to process the page and execute the PHP script.
0
 
LVL 7

Author Comment

by:weikelbob
ID: 11937713
Can't figure it out.  My code is above.
0
 
LVL 33

Expert Comment

by:humeniuk
ID: 11938203
At first glance it looks like it should work.  If there are no other suggestions before tomorrow morning, I'll test them out on my server and see if I can figure out where the problem is.
0
 
LVL 7

Author Comment

by:weikelbob
ID: 11938761
Tried it again, I hit submit and then I get a blank page.
0
 
LVL 9

Expert Comment

by:techtonik
ID: 11939232
Change string
  $org    = 'Grandma's Page.';
to
  $org    = 'Grandma\'s Page.';

And string
  $to_address = "weikelbob@aol.com";
to
  $to = "weikelbob@aol.com";

0
 
LVL 7

Author Comment

by:weikelbob
ID: 11939319
Much better, but now it always says no matter what I put in the form:

Error: Mail cannot be sent plese contact webmaster/techinal department
You will be redirected in 5 seconds
alternatively click here
0
 
LVL 1

Expert Comment

by:magicMush
ID: 11940980
Hi, weikelbob

I am sorry it is my mistake I have forgotten to change one of the fields.

if you notice the mail(.........) line

this code posts the email however if you look at it carefully you could see tht $to and $to_address do not match

instead it should be
if( mail($to_address, $subject, $body, $head))
other one is that
$org    = 'Grandma's Page.';  
as you can see we are using single quotes and adding additional quote on Grandma' <<  will break the string
php will think it is end of the Variable it should be escaped as
$org    = 'Grandma\'s Page.';  this will tell the php to take it as a character instead of end of string.
Below code has been tested  and works fine with your form there was 2 typo mistakes.

-----------------------------
<?php
  $to_address = "botan6@hotmail.com";
  $subject = "From Grandma's Page";
  $message = $_POST['name']."<br>".$_POST['email']."<br>".$_POST['message']."<br>";
  $from = $_POST['name']."<".$_POST['email'].">";
  $rp    = $_POST['email'];
  $org    = 'Grandma\'s Page.';
  $mailer = 'MKSR-Postimies';


  $head  = '';
  $head  .= "Content-Type: text/html \r\n";
  $head  .= "Date: ". date('r'). " \r\n";
  $head  .= "Return-Path: $rp \r\n";
  $head  .= "From: $from \r\n";
  $head  .= "Sender: $from \r\n";
  $head  .= "Reply-To: $from \r\n";
  $head  .= "Organization: $org \r\n";
  $head  .= "X-Sender: $from \r\n";
  $head  .= "X-Priority: 3 \r\n";
  $head  .= "X-Mailer: $mailer \r\n";

  $body= str_replace("\r\n", "\n", $message);
  $body = str_replace("\n", "\r\n", $message);

if( mail($to_address, $subject, $body, $head))
{
?>
<!--write your additional code here to make the page look nicer such as title,some images more user

friendly stuff-->
<h3>Mail has been sent Successfully</h3>
<p>You will be redirected in 5 seconds <br> alternatively <a href="http://www.b-transfers.com/helen

/contact.html">click here</a></p>
<meta http-equiv="REFRESH" content="5;url=http://www.b-transfers.com/helen/contact.html")">
<?php
}
else{
?>
<!--AND HERE write your additional code here to make the page look nicer-->
<h3>Error: Mail cannot be sent plese contact webmaster/techinal department</h3>
<p>You will be redirected in 5 seconds <br> alternatively <a href="http://www.b-transfers.com/helen

/contact.html">click here</a></p>
<meta http-equiv="REFRESH" content="5;url=http://www.b-transfers.com/helen/contact.html")">
<?php
}
?>



0
 
LVL 33

Expert Comment

by:humeniuk
ID: 11941008
I made the changes that techtonik suggested and tested the script on my server.  It works fine.  You can see it in action at www.humeniuk.com/ee_test4/mailpage.php.

The full pages are below.


1. mailpage.php - you can add as much html as you want to the form page


<html>
<head>
<title>Test Mail page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="send_mail.php" method="POST" name="send_mail" id="send_mail">                    
               <p style="text-align: left">&nbsp;</p>
               <p style="text-align: left">Your Name:&nbsp;
               <input type="text" name="name" size="29"></p>
               <p style="text-align: left">Your e-mail:&nbsp;
                <input type="text" name="email" size="29"></p>
               <p style="text-align: left"><span style="vertical-align: top">
                <font face="Arial">Comments: </font></span>&nbsp;<textarea rows="7" name="message" cols="41"></textarea></p>
               <p style="text-align: left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="submit" value="Submit" name="B1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="reset" value="Reset" name="B2"></p>
          </form>
</body>
</html>



2) send_mail.php


<?php
  $to = "weikelbob@aol.com";
  $subject = "From Grandma's Page";
  $message = $_POST['name']."<br>".$_POST['email']."<br>".$_POST['message']."<br>";
  $from = $_POST['name']."<".$_POST['email'].">";
  $rp    = $_POST['email'];
  $org    = 'Grandma\'s Page.';
  $mailer = 'MKSR-Postimies';

  $head  = '';
  $head  .= "Content-Type: text/html \r\n";
  $head  .= "Date: ". date('r'). " \r\n";
  $head  .= "Return-Path: $rp \r\n";
  $head  .= "From: $from \r\n";
  $head  .= "Sender: $from \r\n";
  $head  .= "Reply-To: $from \r\n";
  $head  .= "Organization: $org \r\n";
  $head  .= "X-Sender: $from \r\n";
  $head  .= "X-Priority: 3 \r\n";
  $head  .= "X-Mailer: $mailer \r\n";

  $body= str_replace("\r\n", "\n", $message);
  $body = str_replace("\n", "\r\n", $message);

if( mail($to, $subject, $body, $head))
{
?>
<!--write your additional code here to make the page look nicer such as title,some images more user

friendly stuff-->
<h3>Mail has been sent Successfully</h3>
<p>You will be redirected in 5 seconds <br> alternatively <a href="http://www.b-transfers.com/helen/contact.html">click here</a></p>
<meta http-equiv="REFRESH" content="5;url=http://www.b-transfers.com/helen/contact.html")">
<?php
}
else{
?>
<!--AND HERE write your additional code here to make the page look nicer-->
<h3>Error: Mail cannot be sent plese contact webmaster/techinal department</h3>
<p>You will be redirected in 5 seconds <br> alternatively <a href="http://www.b-transfers.com/helen/contact.html">click here</a></p>
<meta http-equiv="REFRESH" content="5;url=http://www.b-transfers.com/helen/contact.html")">
<?php
}
?>
0
 
LVL 1

Expert Comment

by:magicMush
ID: 11941044
oops.
and dont forget to change it to your email address please
I'll end up receiving all your emails :)

hope this helps.
0
 
LVL 33

Expert Comment

by:humeniuk
ID: 11941133
You don't want email from Grandma's page, magicMush?    :-)
0
 
LVL 7

Author Comment

by:weikelbob
ID: 11948916
Hello,

I'm still getting an error message, I am wondering if my form needs to be redone or if my contact page
needs to have be changed to a php file?  There is no <php> script in the contact page, just the form:

<form action="send_mail.php" method="POST" name="send_mail" id="send_mail">                                      
               <p style="text-align: left">&nbsp;</p>
               <p style="text-align: left">Your Name:&nbsp;
               <input type="text" name="name" size="29"></p>
               <p style="text-align: left">Your e-mail:&nbsp;
                <input type="text" name="email" size="29"></p>
               <p style="text-align: left"><span style="vertical-align: top">
                <font face="Arial">Comments: </font></span>&nbsp;<textarea rows="7" name="message" cols="41"></textarea></p>
               <p style="text-align: left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="submit" value="Submit" name="B1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <input type="reset" value="Reset" name="B2"></p>
          </form>
0
 
LVL 1

Expert Comment

by:magicMush
ID: 11951847
form seems correct

make sure your php file and contact file(Where the form is ) are in the same folder(Directory)
apart from that dont see any reasons why it shuoldnt work and the codes have been tested by myself and humeniuk


0
 
LVL 33

Expert Comment

by:humeniuk
ID: 11955444
Agreed.  But yes, make sure your contact page is 'contact.php' rather than 'contact.html'.
0
 
LVL 7

Author Comment

by:weikelbob
ID: 11959275
Thank you guys, I'll check it out.

I'm really busy with advertising right now, I should be able to get back to this when I'm done.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now