Jump to content


Photo

Simple Email Form

php contact subscribe email address

  • Please log in to reply
9 replies to this topic

#1 Charlott

Charlott

    Newbie

  • New Members
  • Pip
  • 5 posts

Posted 20 January 2013 - 11:46 AM

Right so i'm trying to make a subscribe page at the moment for my website. I've got a section that's listed be the first one to see it here...from there i wanted to make a text box for the user to type their email address and then a button to submit and send me an email of the users email address.

Also, I wanted to make the submit button my own graphic and not just a button?
The HTML code is:

<form class="email" action="mailer.php" method="post">
<input name="email" type="text" size="70" />
<input class="send" type="submit" value="Send">
</form>

and the PHP:


<?php
/* Set e-mail recipient */
$myemail = "cweyer@hotmail.co.uk";

/* Check all form inputs using check_input function */

$email = check_input($_POST['email']);


/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}


/* Send the message using mail() function */
mail($myemail);

/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>

</body>
</html>
<?php
exit();
}
?>




If anyone could help it would be so appreciated! To get more of an idea on my problem, visit www.itscharlottesweb.co.uk

#2 Kristoff1875

Kristoff1875

    Advanced Member

  • Members
  • PipPipPip
  • 235 posts
  • LocationBirmingham UK

Posted 20 January 2013 - 12:23 PM

The submit button can be done in CSS or you can use:
<INPUT TYPE="image" SRC="yourimage.jpg"
			   WIDTH="x"  HEIGHT="x"
			  BORDER="0" ALT="SUBMIT!">

Where height and width are the size of the image.

#3 Kristoff1875

Kristoff1875

    Advanced Member

  • Members
  • PipPipPip
  • 235 posts
  • LocationBirmingham UK

Posted 20 January 2013 - 12:24 PM

Have you uploaded mailer.php?

#4 Charlott

Charlott

    Newbie

  • New Members
  • Pip
  • 5 posts

Posted 20 January 2013 - 04:09 PM

I have uploaded both the HTML file and mailer.php but it still seems to run an error. Brilliant, ill give the button a try! Thanks

#5 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 20 January 2013 - 04:20 PM

:psychic: an error. Mhm.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#6 Kristoff1875

Kristoff1875

    Advanced Member

  • Members
  • PipPipPip
  • 235 posts
  • LocationBirmingham UK

Posted 20 January 2013 - 04:28 PM

I have uploaded both the HTML file and mailer.php but it still seems to run an error. Brilliant, ill give the button a try! Thanks


Earlier on it didn't get to the php page, it just loaded an error. I've just tried another and it's given the thank you message....

#7 Charlott

Charlott

    Newbie

  • New Members
  • Pip
  • 5 posts

Posted 20 January 2013 - 05:35 PM

Working perfectly now, thanks for the help!

#8 Charlott

Charlott

    Newbie

  • New Members
  • Pip
  • 5 posts

Posted 20 January 2013 - 05:44 PM

One last quick question. I'm trying to centre the form. I've got:
<form method="post" name="myemailform" action="form-to-email.php">
<p>;</p>
<p><br>
<input name="email" type="text" size="70">
</p>
<p>


<input type="image" SRC="subscribe.png"
WIDTH="85" HEIGHT="35"
BORDER="0" ALT="SUBMIT!">
</p>

</form>



and am trying to centre it. Anyone got any suggestions?

#9 Charlott

Charlott

    Newbie

  • New Members
  • Pip
  • 5 posts

Posted 20 January 2013 - 06:16 PM

Solved with a few Divs. Thank you everyone for your help

#10 Kristoff1875

Kristoff1875

    Advanced Member

  • Members
  • PipPipPip
  • 235 posts
  • LocationBirmingham UK

Posted 21 January 2013 - 08:00 AM

If you want it to look more like your original design, you can style the text box too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com