-1

My issue: I'm trying to make this form both email the form data and redirect to download page using php script (i.e.: One click = 2 actions). I searched the boards and didn't really find anything similar to what I am trying to do. I had tried several options code wise, but it won't send the email at all. What am I doing wrong?

code: form:

<form id="myform">
<form method="get" action="action/php">
<fieldset><center>
<h3>DOWNLOAD DVD</h3>
<p> Enter your full name and email and then press Download DVD. </p>

<p><br>

<label>Enter Your Name *</label>
<input type="text" name="name" pattern="[a-zA-Z ]{5,}" maxlength="30" />
</p>

<p>
<label>Enter Your Email *</label>
<input type="email" name="email" required />
</p>



<button type="submit" id="submit-myform"; class="submit" value="Submit" name="myform_submit">Download DVD</button>
<button type="reset">Reset</button>
</fieldset>
</form>

php:

<?PHP

if(isset($_POST['myform_submit']) && $_POST['myform_submit'] == "Submit"){

echo "http://www.website.com"; 

}else {
mail( "info@website.com", "Landing Page Download",
$name, "From: $email" );
}
?>

Again ... The download content comes up nicely. But the email will not send.

  • 1
    have you defined $name and $email? Perhaps you meant $_POST['name'] and $_POST['email'] - I see that your mail is in the else. But it kind of doesn't make sense there. Also is your server configured to send mail? and also, action/php actually resolves to this file? – Kai Qing Jan 24 '14 at 02:58

1 Answers1

1

I think you've got your if statement mixed up. Currently it's saying if the form is submitted, then print a URL to the screen, otherwise send an email but from what you've said you want to redirect and send an email. Try this:

if(isset($_POST['myform_submit'])) {
    $send = mail( "info@website.com", "Landing Page Download", $_POST['name'], "From: " . $_POST['email'] );
    if($send) {
        header("Location: http://www.website.com");
    } else {
        echo 'Error sending email!';
    }
}

Problem number 2 is you have nested forms. Not sure why you're doing this, but it's against HTML spec and will probably cause your form data not to get sent as it should. Remove the outer form. Here's line 3 of the HTML3(old!) spec:

Note you are not allowed to nest FORM elements!

Problem number 3, you're setting your form method as GET and then trying to access POST variables. Problem 3.5, your action is action/php - thats not a filename (unless you have an index.php file inside a folder called php, inside a folder called action). Change all this to:

<form method="post" id="myform" action="action.php">

Note: header("Location: [url]") sends a redirect header to your browser, so you are redirected to the target URL. If you simply want to display the URL (like in your question) then continue to just echo it.

Community
  • 1
  • 1
scrowler
  • 24,273
  • 9
  • 60
  • 92
  • It didn't work. Now it won't display the download page and it still doesn't send email. Any other suggestions based on my previous code? – user3230291 Jan 25 '14 at 04:22