Reputation: 1
So I managed to get a form with name, email and a message working and now Im trying to make another one for a sort-of "Stay tuned" function, but I can't get it to work for the life of me. I hope someone can point out the (probably) blatant mistake.
HTML:
<fieldset>
<form class="subscriptionForm" method="post" action="mail.php">
<input name="email" id="subscriptionForm" class="inputForm" type="text" value="Your Email" onFocus="if (this.value=='Your Email') this.value=''" onBlur="if (this.value==''){this.value='Enter Your Email Address'}" />
<input name="submit" type="submit" id="submitButton" class="transition" value="Send">
</form>
</fieldset>
PHP:
<?php
$email = $_POST['email'];
$from = 'From: Studio Westend';
$to = '[email protected]';
$subject = 'Studio Westend Mailing List';
$body = "From: E-Mail: $email\n";
if (mail ($to, $subject, $body, $from, "-f [email protected]"))
echo '<p>Your E-mail has been added!</p>'
?>
And for comparison the code of the other form:
HTML:
<form method="post" action="contact.php" name="contactform" id="contactform">
<input name="name" type="text" id="name" onFocus="if(this.value == 'Name') { this.value = ''; }" onBlur="if(this.value == '') { this.value = 'Name'; }" value="Name" >
<input name="email" type="text" id="email" onFocus="if(this.value == 'E-mail') { this.value = ''; }" onBlur="if(this.value == '') { this.value = 'E-mail'; }" value="E-mail" >
<textarea name="message" id="message" onFocus="if(this.value == 'Message') { this.value = ''; }" onBlur="if(this.value == '') { this.value = 'Message'; }" >Message</textarea>
<input type="submit" class="send_message transition" id="submit" value="Send Message" />
</form>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Studio Westend';
$to = '[email protected]';
$subject = 'Studio Westend Rent Form';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if (mail ($to, $subject, $body, $from, "-f [email protected]"))
echo '<p>Your message has been sent!</p>'
?>
Upvotes: 0
Views: 195
Reputation: 786
<form class="subscriptionForm" method="post" action="mail.php">
<input name="email" id="subscriptionForm" class="inputForm" type="text" value="Your Email" onFocus="if (this.value=='Your Email') this.value=''" onBlur="if (this.value==''){this.value='Enter Your Email Address'}" />
<input name="form1" type="submit" id="submitButton" class="transition" value="Send">
</form>
</fieldset>
<?php
if(isset($_POST['form1'])){
$email = $_POST['email'];
$from = 'From: Studio Westend';
$to = '[email protected]';
$subject = 'Studio Westend Mailing List';
$body = "From: E-Mail: $email\n";
if (mail ($to, $subject, $body, $from, "-f [email protected]"))
echo '<p>Your E-mail has been added!</p>'
}
?>
============Other form========
<form method="post" action="contact.php" name="contactform" id="contactform">
<input name="name" type="text" id="name" onFocus="if(this.value == 'Name') { this.value = ''; }" onBlur="if(this.value == '') { this.value = 'Name'; }" value="Name" >
<input name="email" type="text" id="email" onFocus="if(this.value == 'E-mail') { this.value = ''; }" onBlur="if(this.value == '') { this.value = 'E-mail'; }" value="E-mail" >
<textarea name="message" id="message" onFocus="if(this.value == 'Message') { this.value = ''; }" onBlur="if(this.value == '') { this.value = 'Message'; }" >Message</textarea>
<input type="submit" name="form2" class="send_message transition" id="submit" value="Send Message" />
</form>
<?php
if(isset($_POST['form2'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Studio Westend';
$to = '[email protected]';
$subject = 'Studio Westend Rent Form';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if (mail ($to, $subject, $body, $from, "-f [email protected]"))
echo '<p>Your message has been sent!</p>'
}
?>
Note: Your code is not safe. Note2: You should give to every form's submit button a different name, and you should use if() to determine if the button is clicked. This should work.
Upvotes: 1
Reputation: 459
No 2 fields in the same page should have the same name and id. Try giving full url for form action attribute,ie with site url ex site_url/page.
<fieldset>
<form class="subscriptionForm" method="post" action="mail.php">
<input name="email" id="subscriptionForm" class="inputForm" type="text"
value="Your Email"
onFocus="if (this.value=='Your Email') this.value=''"
onBlur="if (this.value==''){this.value='Enter Your Email Address'}" />
<input name="submit" type="submit" id="submitButton" class="transition" value="Send">
</form>
</fieldset>
<?php
$email = $_POST['email'];
$from = 'From: Studio Westend';
$to = '[email protected]';
$subject = 'Studio Westend Mailing List';
$body = "From: E-Mail: $email\n";
if (mail ($to, $subject, $body, $from, "-f [email protected]"))
echo '<p>Your E-mail has been added!</p>'
?>
<form method="post" action="contact.php" name="contactform" id="contactform">
<input name="name" type="text" id="name"
onFocus="if(this.value == 'Name') { this.value = ''; }"
onBlur="if(this.value == '') { this.value = 'Name'; }" value="Name" >
<input name="contact_email" type="text" id="contact_email"
onFocus="if(this.value == 'E-mail') { this.value = ''; }"
onBlur="if(this.value == '') { this.value = 'E-mail'; }" value="E-mail" >
<textarea name="message" id="message"
onFocus="if(this.value == 'Message') { this.value = ''; }"
onBlur="if(this.value == '') { this.value = 'Message'; }" >Message</textarea>
<input type="submit" class="send_message transition" id="submit" value="Send Message" />
</form>
<?php
$name = $_POST['name'];
$email = $_POST['contact_email'];
$message = $_POST['message'];
$from = 'From: Studio Westend';
$to = '[email protected]';
$subject = 'Studio Westend Rent Form';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if (mail ($to, $subject, $body, $from, "-f [email protected]"))
echo '<p>Your message has been sent!</p>'
?>
Upvotes: 0