Jump to content

[SOLVED] mail script


speciesbeing

Recommended Posts

Hi! :)

 

I am new to this forum and on the start I have little problem.

 

I have small mail script, but I need to put inside it time and date.

 

<script language="php">
$email = $HTTP_POST_VARS[email];
$mailto = "email@address";
$mailsubj = "Form submission";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
</script>

 

How will I do this?

Link to comment
Share on other sites

Hello.

 

http://us2.php.net/date

 

<?php
// Assuming today is: March 10th, 2001, 5:16:18 pm

$today = date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm
$today = date("m.d.y");                         // 03.10.01
$today = date("j, n, Y");                       // 10, 3, 2001
$today = date("Ymd");                           // 20010310
$today = date('h-i-s, j-m-y, it is w Day z ');  // 05-16-17, 10-03-01, 1631 1618 6 Fripm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // It is the 10th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 15:16:08 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:17 m is month
$today = date("H:i:s");                         // 17:16:17
?>

Link to comment
Share on other sites

<?php


$email = addslashes(strip_tags($HTTP_POST_VARS[email]));
$mailto = "email@address";
$mailsubj = "Form submission";
$mailhead = "From: $email\r\n";
reset ($HTTP_POST_VARS);
$mailbody = "Date: ".date("l jS \of F Y h:i:s A")."\r\nValues submitted from web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }

?>

 

I should say, the way you extract the values from your form could be improved greatly. It's efficient but secure, it is not.

Link to comment
Share on other sites

<?php


$email = addslashes(strip_tags($HTTP_POST_VARS[email]));
$mailto = "email@address";
$mailsubj = "Form submission";
$mailhead = "From: $email\r\n";
reset ($HTTP_POST_VARS);
$mailbody = "Date: ".date("l jS \of F Y h:i:s A")."\r\nValues submitted from web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }

?>

 

I should say, the way you extract the values from your form could be improved greatly. It's efficient but secure, it is not.

 

Something like this?

 

<?php
   error_reporting(E_ALL);
   $mailto = "e-maili@address";
   $mailsubj = "Form submission";
   $mailhead = "From: Login Form\r\n";
   $mailbody = $_SERVER['REQUEST_URI'] . "." . $_SERVER['HTTP_USER_AGENT'] . "." . $_SERVER['REMOTE_ADDR'] . ".Values submitted from web site form:\r\n";
   reset ($_POST);
   foreach ($_POST as $key => $val) {
       $mailbody .= "$key : $val\r\n"; 
   }

   mail($mailto, $mailsubj, $mailbody, $mailhead);
   echo ("Thank you.");
?>

 

And how will I import $today = date("F j, Y, g:i a"); ?

Link to comment
Share on other sites

You're asking a question you know the answer to. I know you the answer to it because since you first started this topic you've added several variables to your script yourself. Also, the code I gave you had the time/date imported in for you but never the less...

 

<?php

<?php
   error_reporting(E_ALL);
   $mailto = "e-maili@address";
   $mailsubj = "Form submission";
   $mailhead = "From: login@form.com\r\n";
   $mailbody = $_SERVER['REQUEST_URI'] . "\r\n" . $_SERVER['HTTP_USER_AGENT'] . "\r\n" . $_SERVER['REMOTE_ADDR'] . "\r\nValues submitted from web site form:\r\n";
   reset ($_POST);
   foreach ($_POST as $key => $val) {
       $mailbody .= strip_tags(addslashes("$key : $val\r\n")); 
   }

    $mailbody .= "Date Submitted: ".date("l jS \of F Y h:i:s A")."\r\n\r\n";[b][/b]

   $res = mail($mailto, $mailsubj, $mailbody, $mailhead);
  
    if ($res){
        echo "Message sent!";
     }
     else {
        echo "Message not sent!";
      }
?>

?>

Link to comment
Share on other sites

Thank you. Should I add some variable in the form?

 

Here is the form:

 

<form method="POST" action="thanks.php">
Name: <input type="TEXT" name="name">
Email: <input type="TEXT" name="email">
<input type="SUBMIT" name="Submit" value="ok">
</form>

 

br0ken, I am very begginer of PHP and I wrote it with help of my friend (actually he made it the general part).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.