Jump to content

Email Script Help


geekette

Recommended Posts

So basically what I'm trying to do is create an <input> text field at the end of the revieworder.php file, where the user puts their email address, hits confirm, and then an automated email message gets sent to them. unfortunately, I keep receiving the "mail failed" echo.  I probably don't have the correct code, but any help would be appreciated! I've also included the .html and .css files as a background reference:

 

 

.html:

 

<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<title> Princess Cupcakes </title>
</head>
<body>
<link rel="stylesheet" href="phpcssstyle.css" type="text/css" />
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />


<h1>Princess Cupcakes<h1 /> <hr> <hr />
<h2>Warming hearts one cupcake at a time.</h2>
<br>
<h3>All cupcakes are $2.50 each unless otherwise noted. Please allow at least 20 minutes between order and pickup time.</h3>
<br /> <hr> <hr />

<ul><b>
<li>Pink Princess: Strawberry cupcake with a strawberry whipped cream frosting
<li> Swan Princess: Vanilla cupcake with lemon buttercream frosting
<li>Prince Charming: Chocolate cupcake with a raspberry buttercream frosting
<li>Royal Crown: Red velvet cupcake with cheesecake frosting
<li>The Nutty Jester: Nutella filled cupcake, with a nutella buttercream frosting
<li>Pumpkin Carriage: Pumpkin cupcake with a pumpkin whipped cream frosting
<li>Princess Diaries: Blueberry cupcake with blueberry whipped cream frosting
<li>Tropical Princess: Mango and banana cupcake with a strawberry whipped cream frosting
<li>Career Princess: Vanilla cake with dark chocolate buttercream frosting
</b>
<br>
<br>
<br />
<h3>Order your cupcakes here. For quantities over 5 per type of cupcake, please call us:
<form action="ReviewOrder.php" method="get">
<p><b>Pink Princess</b></p>
<p><input type="radio" name="pp" value="0" />Zero<br />
<input type="radio" name="pp" value="1" />One<br />
<input type="radio" name="pp" value="2" />Two <br />
<input type="radio" name="pp" value="3" />Three<br />
<input type="radio" name="pp" value="4" />Four<br />
<input type="radio" name="pp" value="5" />Five</p>
<br>
<p><b>Swan Princess</b></p>
<p><input type="radio" name="sp" value="0" />Zero<br />
<input type="radio" name="sp" value="1" />One<br />
<input type="radio" name="sp" value="2" />Two<br />
<input type="radio" name="sp" value="3" />Three<br />
<input type="radio" name="sp" value="4" />Four<br />
<input type="radio" name="sp" value="5" />Five</p>
<br>
<p><b>Prince Charming</b></p>
<p><input type="radio" name="pc" value="0" />Zero<br />
<input type="radio" name="pc" value="1" />One<br />
<input type="radio" name="pc" value="2" />Two<br />
<input type="radio" name="pc" value="3" />Three<br />
<input type="radio" name="pc" value="4" />Four<br />
<input type="radio" name="pc" value="5" />Five</p>
<br>
<p><b>Royal Crown</b></p>
<p><input type="radio" name="rc" value="0" />Zero<br />
<input type="radio" name="rc" value="1" />One<br />
<input type="radio" name="rc" value="2" />Two<br />
<input type="radio" name="rc" value="3" />Three<br />
<input type="radio" name="rc" value="4" />Four<br />
<input type="radio" name="rc" value="5" />Five</p>
<br>
<p><b>The Nutty Jester</b></p>
<p><input type="radio" name="nj" value="0" />Zero<br />
<input type="radio" name="nj" value="1" />One<br />
<input type="radio" name="nj" value="2" />Two<br />
<input type="radio" name="nj" value="3" />Three<br />
<input type="radio" name="nj" value="4" />Four<br />
<input type="radio" name="nj" value="5" />Five</p>
<br>
<p><b>Pumpkin Carriage</b></p>
<p><input type="radio" name="pkc" value="0" />Zero<br />
<input type="radio" name="pkc" value="1" />One<br />
<input type="radio" name="pkc" value="2" />Two<br />
<input type="radio" name="pkc" value="3" />Three<br />
<input type="radio" name="pkc" value="4" />Four<br />
<input type="radio" name="pkc" value="5" />Five</p>
<br>
<p><b>Princess Diaries</b></p>
<p><input type="radio" name="pd" value="0" />Zero<br />
<input type="radio" name="pd" value="1" />One<br />
<input type="radio" name="pd" value="2" />Two<br />
<input type="radio" name="pd" value="3" />Three<br />
<input type="radio" name="pd" value="4" />Four<br />
<input type="radio" name="pd" value="5" />Five</p>
<br>
<p><b>Tropical Princess</b></p>
<p><input type="radio" name="tp" value="0" />Zero<br />
<input type="radio" name="tp" value="1" />One<br />
<input type="radio" name="tp" value="2" />Two<br />
<input type="radio" name="tp" value="3" />Three<br />
<input type="radio" name="tp" value="4" />Four<br />
<input type="radio" name="tp" value="5" />Five</p>
<br>
<p><b>Career Princess</b></p>
<p><input type="radio" name="cp" value="0" />Zero<br />
<input type="radio" name="cp" value="1" />One<br />
<input type="radio" name="cp" value="2" />Two<br />
<input type="radio" name="cp" value="3" />Three<br />
<input type="radio" name="cp" value="4" />Four<br />
<input type="radio" name="cp" value="5" />Five</p>
<br>
<br>
<p><input type="submit" value="Okay" /></p>
</form>

<body />
<html />

 

.css file

 

body {

  color: white;

  background: pink;

  margin-bottom: 6ex;

  font-family: Verdana, Arial, Helvetica, sans-serif;

  font-size: 12px;

}



h1 {

  color: #039;

  background: pink;

  margin-bottom: 2ex;

}



h2, h3, h4, h5, h6 {

  color: #039;

}



table {

  margin-right: auto;

  margin-bottom: 2ex;

}



thead td, th {

  color: black;

  background: #cccccc;

  font-size: smaller;

  font-weight: bold;

  text-align: center;

  padding: 0.5em 1ex;

  border: 1pt solid gray;

}



tbody td, td {

  color: black;

  background: #eeeeee;

  font-size: small;

  padding: 0.5em 1ex;

  border: 1pt solid gray;

}



pre {

  color: white;

  font-family: Verdana, Arial, Helvetica, sans-serif;

  font-size: 12px;

}

 

this is the .php that connects to the .html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Review Order</title>
</head>
<body>
<link rel="stylesheet" href="phpcssstyle.css" type="text/css" />

<h1>Review Order</h1>
<?php

function reviewpp ( ) {
echo "<p>Pink Princess: ", $_GET [ "pp" ];
if ($_GET["pp"] == "0")
echo " (Zero)</p>";
if ($_GET["pp"] == "1")
echo " (One)</p>";
if ($_GET["pp"] == "2")
echo " (Two)</p>";
if ($_GET["pp"] == "3")
echo " (Three)</p>";
if ($_GET["pp"] == "4")
echo " (Four)</p>";
if ($_GET["pp"] == "5")
echo " (Five)</p>";
}

function reviewsp ( ) {
echo "<p>Swan Princess: ", $_GET [ "sp" ];
if ($_GET["sp"] == "0")
echo " (Zero)</p>";
if ($_GET["sp"] == "1")
echo " (One)</p>";
if ($_GET["sp"] == "2")
echo " (Two)</p>";
if ($_GET["sp"] == "3")
echo " (Three)</p>";
if ($_GET["sp"] == "4")
echo " (Four)</p>";
if ($_GET["sp"] == "5")
echo " (Five)</p>";
}

function reviewpc ( ) {
echo "<p>Prince Charming: ", $_GET [ "pc" ];
if ($_GET["pc"] == "0")
echo " (Zero)</p>";
if ($_GET["pc"] == "1")
echo " (One)</p>";
if ($_GET["pc"] == "2")
echo " (Two)</p>";
if ($_GET["pc"] == "3")
echo " (Three)</p>";
if ($_GET["pc"] == "4")
echo " (Four)</p>";
if ($_GET["pc"] == "5")
echo " (Five)</p>";
}

function reviewrc ( ) {
echo "<p>Royal Crown: ", $_GET [ "rc" ];
if ($_GET["rc"] == "0")
echo " (Zero)</p>";
if ($_GET["rc"] == "1")
echo " (One)</p>";
if ($_GET["rc"] == "2")
echo " (Two)</p>";
if ($_GET["rc"] == "3")
echo " (Three)</p>";
if ($_GET["rc"] == "4")
echo " (Four)</p>";
if ($_GET["rc"] == "5")
echo " (Five)</p>";
}

function reviewnj ( ) {
echo "<p>The Nutty Jester: ", $_GET [ "nj" ];
if ($_GET["nj"] == "0")
echo " (Zero)</p>";
if ($_GET["nj"] == "1")
echo " (One)</p>";
if ($_GET["nj"] == "2")
echo " (Two)</p>";
if ($_GET["nj"] == "3")
echo " (Three)</p>";
if ($_GET["nj"] == "4")
echo " (Four)</p>";
if ($_GET["nj"] == "5")
echo " (Five)</p>";
}

function reviewpkc ( ) {
echo "<p>Pumpkin Carriage: ", $_GET [ "pkc" ];
if ($_GET["pkc"] == "0")
echo " (Zero)</p>";
if ($_GET["pkc"] == "1")
echo " (One)</p>";
if ($_GET["pkc"] == "2")
echo " (Two)</p>";
if ($_GET["pkc"] == "3")
echo " (Three)</p>";
if ($_GET["pkc"] == "4")
echo " (Four)</p>";
if ($_GET["pkc"] == "5")
echo " (Five)</p>";
}

function reviewpd ( ) {
echo "<p>Princess Diaries: ", $_GET [ "pd" ];
if ($_GET["pd"] == "0")
echo " (Zero)</p>";
if ($_GET["pd"] == "1")
echo " (One)</p>";
if ($_GET["pd"] == "2")
echo " (Two)</p>";
if ($_GET["pd"] == "3")
echo " (Three)</p>";
if ($_GET["pd"] == "4")
echo " (Four)</p>";
if ($_GET["pd"] == "5")
echo " (Five)</p>";
}

function reviewtp ( ) {
echo "<p>Tropical Princess: ", $_GET [ "tp" ];
if ($_GET["tp"] == "0")
echo " (Zero)</p>";
if ($_GET["tp"] == "1")
echo " (One)</p>";
if ($_GET["tp"] == "2")
echo " (Two)</p>";
if ($_GET["tp"] == "3")
echo " (Three)</p>";
if ($_GET["tp"] == "4")
echo " (Four)</p>";
if ($_GET["tp"] == "5")
echo " (Five)</p>";
}

function reviewcp ( ) {
echo "<p>Career Princess: ", $_GET [ "cp" ];
if ($_GET["cp"] == "0")
echo " (Zero)</p>";
if ($_GET["cp"] == "1")
echo " (One)</p>";
if ($_GET["cp"] == "2")
echo " (Two)</p>";
if ($_GET["cp"] == "3")
echo " (Three)</p>";
if ($_GET["cp"] == "4")
echo " (Four)</p>";
if ($_GET["cp"] == "5")
echo " (Five)</p>";
}

reviewpp ( );
reviewsp ( );
reviewpc ( );
reviewrc( );
reviewnj ( );
reviewpkc ( );
reviewpd ( );
reviewtp ( );
reviewcp ( );


?>

Please enter your email address below and we will send you a confirmation email shortly. If you do not receive a confirmation email, please call us.: 
<Input type="Text" size="30">
<form action="email.php" method="get>
<Input type="Text" size="30">
<p><input type="submit" value="Confirm" /></p>


</body>
</html>

 

the following is the email script, also a .php:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Princess Cupcakes Review Order Email Confirm</title>
</head>
<body>
<link rel="stylesheet" href="phpcssstyle.css" type="text/css" />



<?php

$to =

$subject = 'Princess Cupcakes';

$message = "Thank you for your order. We will have them ready shortly.";

$headers = "From: dessertfiend@gmail.com\r\nReply-To: dessertfiend@gmail.com";

$mail_sent = @mail( $to, $subject, $message, $headers );

echo $mail_sent ? "Mail sent" : "Mail failed";
?>


</body>
</html>

Link to comment
Share on other sites

change this...

<Input type="Text" size="30">
<form action="email.php" method="get>
<Input type="Text" size="30">
<p><input type="submit" value="Confirm" /></p>

to this...

<form action="email.php" method="get>
<Input type="Text" size="30" name="email">
<p><input type="submit" value="Confirm" /></p>
</form>

 

then in the e-mail script.

change this...

$to =

to this...

$to = $_GET['email'];

 

you can also check if the e-mail address entered is valid before you send the e-mail.

 

like this...

function is_email($email) { // Thanks to "mail(at)philipp-louis.de" from php.net!

    return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));

}

if(!is_email($_GET['email'])) {
  die("Not a valid e-mail!");
}

Link to comment
Share on other sites

When I replaced what I had to the following:

 

<form action="email.php" method="get>
<Input type="Text" size="30" name="email">
<p><input type="submit" value="Confirm" /></p>
</form>

 

the field didn't show up. however, when I had it the way I did before, the text field would be there, though, the email still echoed fail after correcting the $to field.

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.