开发者

Form for sending mail not sending

开发者 https://www.devze.com 2023-03-05 16:45 出处:网络
I have a \"tell a friend\" pop up email form that allows users to share my page with an email address that they enter.It pops up fine, but I can\'t get the form to send the email.

I have a "tell a friend" pop up email form that allows users to share my page with an email address that they enter. It pops up fine, but I can't get the form to send the email.

html:

<div id="tellfriend">
      <a href="#close">Close</a>

      <form id='tellafriend_form' method="post" action="#sendMessage" name="tellafriend_form">

        <label for="name">Your Name:</label>
        <input type="text" id="name" name="name" />

        <label for="to">Friend's email:</label> 
        <input type="text" id="to" name="to" /> 

        <label for="subject">Subject:<开发者_如何学JAVA;/label>
        <input type="text" id="subject" name="subject" /> 

        <label for="message">Message:</label> 
        <textarea id="message" name="message"></textarea>
        <input type="submit" name="submit" value="Submit">

      </form>

</div><!-- #tellfriend -->

javascript that handles the "pop up":

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script> 
<script>
$(function() {
    $('#tellfriend').hide();
    $('#sendMessage').click(function(e) {
        $("#tellfriend").fadeToggle('fast');
    });

});
</script>

php that's supposed to send the mail:

<?
if (isset($_POST['Submit'])) {
// This will check to see if the form has been submitted
$senders_name = $_POST['name'];
// The person who is submitting the form
$recipient_friend = $_POST['to'];
// The forms recipient
$subject = $_POST['subject'];
// The subject line
$message = $_POST['message'];
// The message being sent
mail($recipient_friend, "From $senders_name", $subject, $message);

if (isset($_POST['your_email'])) {
echo "<br>Your friend has been contacted <br><br>Thank you $senders_name";
}}
?>

Disclaimer: PHP newbie, hoping to learn. Thanks!


The order of your parameters in mail function is not correct. see this

it should be

mail($recipient_friend, $subject, $message);

if you want to use headers then do this

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";    
$headers .= 'To: '.$recipient_friend.' <'.$recipient_friend.'>' . "\r\n";    
$headers .= 'From: '.$sender.' <'.$senderEM.'>' . "\r\n";    

Then call mail like this

mail($recipient_friend, $subject, $message, $headers);


You have one error in your PHP code:

if (isset($_POST['Submit'])) {

should be:

if (isset($_POST['submit'])) {

with a lowercase "s".

Indeed the name of you submit button is "submit" but the value is "Submit". You could eventually do that:

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

And your mail parameters are not correct like boug said.


You have 2 errors

  1. first:

    if (isset($_POST['submit']))
    // $_POST is case sensitive
    
  2. second:

    if (isset($_POST['your_email']))
    // you dont have an inout named 'your_email'
    
0

精彩评论

暂无评论...
验证码 换一张
取 消