Jump to content

email form


pedrwvargas
 Share

Go to solution Solved by maxxd,

Recommended Posts

It just doesn't work. It does work if I keep it simple with no html involved. What am I doing wrong? Are all those divs inside the form a problem?
 
Thanks!

 

*myemail@gmail.com is changed for my real email in the code so that is not the problem.

<section>
<h2>get in touch</h2>
<?php
if (isset($_REQUEST['email']))  {


$admin_email = 'myemail@gmail.com';
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$message = $_REQUEST['message'];


mail($admin_email, '$name', $message, 'From:' . $email);


echo '<p>your message has been sent and we will reply as soon as possible <br>thanks for being patient</p>';
}


else  {
?>
<form method="post">
<div class="field half first">
<input type="text" name="name" id="name" placeholder="name" />
</div>
<div class="field half">
<input type="email" name="email" id="email" placeholder="email" />
</div>
<div class="field">
<textarea name="message" id="message" rows="4" placeholder="message"></textarea>
</div>
<ul class="actions">
<li><input type="submit" value="send" class="special" /></li>
<li><input type="reset" value="reset" /></li>
</ul>
</form>
<?php
}
?>
</section>

 

Link to comment
Share on other sites

You're going to have to describe the problem more fully than "It just doesn't work". I'm assuming there's no error being displayed as you've got no error checking set up. What doesn't work? The form doesn't display, the mail doesn't send, your cat stops talking to you? Please be more specific and we can try to help you.

 

In the meantime, your script is a veritable playground for script kiddies who want to spam the crap out of everyone everywhere. A user doesn't even have to actually submit your form to send emails. And by simply assuming the from email is actually that, you're opening yourself up to letting a malicious user carbon copy, blind carbon copy, and send directly to anyone he or she wants.

Link to comment
Share on other sites

You're going to have to describe the problem more fully than "It just doesn't work". I'm assuming there's no error being displayed as you've got no error checking set up. What doesn't work? The form doesn't display, the mail doesn't send, your cat stops talking to you? Please be more specific and we can try to help you.

 

In the meantime, your script is a veritable playground for script kiddies who want to spam the crap out of everyone everywhere. A user doesn't even have to actually submit your form to send emails. And by simply assuming the from email is actually that, you're opening yourself up to letting a malicious user carbon copy, blind carbon copy, and send directly to anyone he or she wants.

 

Both the mail doesn't send and my cat stopped talking to me.  I already fixed the cat problem but can't figure out what's wrong with the code other than being for script kiddies who want to spam the crap out of everyone all over the planet Earth and beyond.

 

Now, seriously no error has been displayed so apparently there's no error (but there is lol). I'll try to be more specific next time, sorry about that.

Link to comment
Share on other sites

  • Solution

OK - is anything being displayed? Add

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
?>

to the very top of your script. Do you get an error before you try to submit the form? Or after?

 

Just looking at it, it could be that you're trying to send an email to the literal string '$name' - single quotes in PHP don't allow variable parsing. Plus, they're not necessary in this instance.

 

And all joking aside, please do check into some validation before you use the mail() function. You'll be glad for it later.

Link to comment
Share on other sites

OK - is anything being displayed? Add

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
?>

to the very top of your script. Do you get an error before you try to submit the form? Or after?

 

Just looking at it, it could be that you're trying to send an email to the literal string '$name' - single quotes in PHP don't allow variable parsing. Plus, they're not necessary in this instance.

 

And all joking aside, please do check into some validation before you use the mail() function. You'll be glad for it later.

Problem solved! It had to do with the single quotes. Thank you very much. As for validation I'll have a look and try to apply it to my code.

Link to comment
Share on other sites

Problem solved! It had to do with the single quotes. Thank you very much. As for validation I'll have a look and try to apply it to my code.

 

Please do, and while you're at it you'll want to look at error checking. Together, they'll save you many headaches in the long run. As far as mail-specific things go, in the future you may want to look into PHPMailer - it's safer, more robust, and more reliable than the built-in PHP mail() function.

 

Also, glad the cat's talking to you again.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

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.

 Share

×
×
  • 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.