Jump to content

[SOLVED] Any help with my email script?


Irresistable

Recommended Posts

I have an email script, I have not tested it, although someone tested it for me and said it worked fine. I started to make modifications to the code after using the basic structure. This is my HTML form;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#form1 p {
color: #000;
font-size: 24px;
}
.text {
color: #F00;
font-size: 36px;
}
-->
</style>
</head>

<body>
<span class="text">Email Test Form</span><br />
<form id="form1" name="form1" method="post" action="mailer.php">
  <table width="520" height="255" border="1">
    <tr>
      <td>To: </td>
      <td><input name="to" type="text" id="to" size="75" /></td>
    </tr>
    <tr>
      <td>From:</td>
      <td><input name="from" type="text" id="from" size="75" /></td>
    </tr>
    <tr>
      <td>Subject:</td>
      <td><input name="subject" type="text" id="subject" size="75" /></td>
    </tr>
    <tr>
      <td>Message:</td>
      <td><textarea name="message" cols="72" rows="10" id="message"></textarea></td>
    </tr>
    <tr>
      <td> </td>
      <td><span class="style3"><center><img src="Newsletter Beta/pngimg.php" alt="" width="82" height="32" align="middle" /><br />
          <input name="user_code" type="text" size="10" value="<?php echo $form->value("captcha"); ?>" />
      </center></span></td>
    </tr>
    <tr>
      <td> </td>
      <td><center><input type="submit" name="button" id="button" value="Send" />
      <input type="reset" name="button2" id="button2" value="Reset" /></center></td>
    </tr>
  </table>
</form>
</body>
</html>

 

Now here is the PHP handler for this form;

<?php
$to = "$to";
$from_header = "From: $from";
if($message != "")
{
   //send mail - $subject & $contents come from surfer input
   mail($to, $subject, $contents, $from_header);
   // redirect back to url visitor came from
   header("Location: $HTTP_REFERER");
   print("<HTML><BODY>You're newsletter has been sent.");
   print("</BODY></HTML>");
}
  else
{
   print("<HTML><BODY>Please check your form, there was an error somewhere. If this was not the case, please contact the Administrator.");
   print("</BODY></HTML>");
}
?>

 

There may be faults in this code, let me know if there is and provide a fix if possible.

What I aim to do here.. is like with a register form, submit the details, it gets sent. Afterwards, the form replaces with an "Your mail has been sent" if there was an error, to display ABOVE the form "There was an error processing this mail, please check the form and try again. If this does not solve your problem contact the administrator" or simply label it "goodnews" "badnews"

 

Also, either help me with this or not. Set it with error fields. (Probably will have to make the table with 3 collumns) At the last collumn after each field.. set an error field, so that if it does not get filled in, or its incorrect information, invalid emails (which shouldn't happen.. but just to take precautions) so.. that if something isn't submitted it proceeds with the error field, but doesn't remove the form. Unless its submitted and passed the problems and recieves the goodnews.

I shall note that you DO NOT have to create all error fields, doing ONE, will help me in working out the others.

 

Maybe.. hook up the captcha, although.. I haven't done the captcha properly yet.. many parts missing to it. (The bits that actually create the code) unless your willing to do this aswell.. but I don't expect you to.. I'll sort that out when the rest of this is done, as its last priority.

 

Each paragraph comes in order of prority.. its your choose if you assist with the coding, if not.. some help, and ideas of how to do it will deffinately be useful to me.

 

Thank you.

Link to comment
Share on other sites

Cheers, So It should look like this?

(Here is the updated code)

<?php
$_POST['message'].
$_POST['to']
$_POST['from']
$_POST['subject']

$from_header = "From: $from";
if($message != "")
{
   //send mail - $subject & $contents come from surfer input
   mail($to, $subject, $message, $from_header);
   // redirect back to url visitor came from
   header("Location: $HTTP_REFERER");
   print("<HTML><BODY>You're newsletter has been sent.");
   print("</BODY></HTML>");
}
  else
{
   print("<HTML><BODY>Please check your form, there was an error somewhere. If this was not the case, please contact the Administrator.");
   print("</BODY></HTML>");
}
?>

If correct;

Could you assist with the other things I needed help with on initial post.

Link to comment
Share on other sites

I worked on the error fields.. I might of made a total mess.. assist me with corrections if you can :)

HTML Form

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#form1 p {
color: #000;
font-size: 24px;
}
.text {
color: #F00;
font-size: 36px;
}
-->
</style>
</head>

<body>
<span class="text">Email Test Form</span><br />
<form id="form1" name="form1" method="post" action="mailer.php">
  <table width="691" height="255" border="1">
    <tr>
      <td width="74">To: </td>
      <td width="450"><input name="to" type="text" id="to" size="75"/></td>
      <td width="145"><?php echo $mailer->error("to"); ?></td>
    </tr>
    <tr>
      <td>From:</td>
      <td><input name="from" type="text" id="from" size="75" /></td>
      <td><?php echo $mailer->error("from"); ?></td>
    </tr>
    <tr>
      <td>Subject:</td>
      <td><input name="subject" type="text" id="subject" size="75" /></td>
      <td><?php echo $mailer->error("subject"); ?></td>
    </tr>
    <tr>
      <td>Message:</td>
      <td><textarea name="message" cols="72" rows="10" id="message" ></textarea></td>
      <td><?php echo $mailer->error("message"); ?></td>
    </tr>
    <tr>
      <td> </td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td> </td>
      <td><center><input type="submit" name="button" id="button" value="Send" />
      <input type="reset" name="button2" id="button2" value="Reset" /></center></td>
      <td> </td>
    </tr>
  </table>
</form>
</body>
</html>

 

Form Handler

<?php
$_POST['message'].
$_POST['to']
$_POST['from']
$_POST['subject']

function error($field){
   if(array_key_exists($field,$this->errors)){
      return "<font size=\"2\" color=\"#ff0000\">".$this->errors[$field]."</font>";
   }else{
      return "";
   }
}

if($message != "")
{
/* Recipent error checking */
$field = "email";
if(!$to || strlen($to = trim($to)) == 0){
echo("No Recipent entered!");
}

/* From error checking */
$field = "from";
if(!$from || strlen($from = trim($from)) == 0){
echo("No Sender entered!");
}

/* Subject error checking */
$field = "subject";
if(!$subject || strlen($subject = trim($subject)) == 0){
echo("No Subject Entered");
}

/* Message error checking */
$field = "message";
if(!$message || strlen($message = trim($message)) == 0){
echo("No Message Entered");
}
else
{

   //send mail - $subject & $contents come from surfer input
   mail($to, $subject, $message, $from);
   // redirect back to url visitor came from
   header("Location: $HTTP_REFERER");
   print("<HTML><BODY>You're newsletter has been sent.");
   print("</BODY></HTML>");
  }
}
  else
{
   print("<HTML><BODY>Please check your form, there was an error somewhere. If this was not the case, please contact the Administrator.");
   print("</BODY></HTML>");
}
?>

 

Onsubmit, the form submits the values.. checks for errors, and then if theres errors displays the error in the error fields on the form. Else.. it will send the email to the "to" and from the "from" with the message and subject. It should do anyway.

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.