开发者

Why don't E-mail scripts built into premium templates ever work?

... And the scripts are always so tedious to remove from the site.

I have the following code, in three files:

sendemail.php:

<?php

/************************
* Variables you can change
*************************/

$mailto   = "doodleface@sillydomain.com"; // Enter your mail addres here. 
$name     = ucwords($_POST['name']); 
$subject  = "Message from $name"; // Enter the subject here.
$email    = $_POST['email'];
$message  = $_POST['message'];

    if(strlen($_POST['name']) < 1 ){
        echo  'email_error';
    }

  else if(strlen($email) < 1 ) {
        echo 'email_error';
    }

  else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", $email)) {
    echo 'email_error';
  }

    else if(strlen($message) < 1 ){
        echo 'email_error';

  } else {

    // NOW SEND THE ENQUIRY

    $email_message="\n\n" .
        "Name: " .
        ucwords($name) .
        "\n" .
        "Email: " .
        $email .
        "\n" .
        "Comments: " .
        "\n" .
        $message .
        "\n" .
        "\n\n" ;

        $email_message = trim(stripslashes($email_message));
        mail($mailto, $subject, $email_message, "From: \"$vname\" <".$email.">\nReply-To: \"".ucwords($name)."\" <".$email.">\nX-Mailer: PHP/" . phpversion() );

}
?>

contact-form.js:

  $(document).ready(function() {        
  $('#buttonsend').click( function() {

        var name    = $('#name').val();
        var subject = $('#subject').val();
        var email   = $('#email').val();
        var message = $('#message').val();

        $('.loading').fadeIn('slow');

        if (name != "" && subject != "" && email != "" && message != "")
            {

                $.ajax(
                    {
                        url: './sendemail.php',
                        type: 'POST',
                        data: "name=" + name + "&subject=" + subject + "&email=" + email + "&message=" + message,
                        success: function(result) 
                        {
                            $('.loading').fadeOut('fast');
                            if(result == "email_error") {
                                $('#email').css({"border":"1px solid #FF8C8C"}).next('.require').text(' !');
     开发者_如何学运维                       } else {
                                $('#name, #subject, #email, #message').val("");
                                $('<div class="success">Your message has been sent successfully. Thank you! </div>').insertBefore('#maincontactform');
                                $('.success').fadeOut(5000, function(){ $(this).remove(); });
                            }
                        }
                    }
                );
                return false;

            } 
        else 
            {
                $('.loading').fadeOut('fast');
                if( name == "") $('#name').css({"background":"#FFFCFC","border":"1px solid #FFD1D1"}).next('.require').text(' !');
                if(subject == "") $('#subject').css({"background":"#FFFCFC","border":"1px solid #FFD1D1"}).next('.require').text(' !');
                if(email == "" ) $('#email').css({"background":"#FFFCFC","border":"1px solid #FFD1D1"}).next('.require').text(' !');
                if(message == "") $('#message').css({"background":"#FFFCFC","border":"1px solid #FFD1D1"}).next('.require').text(' !');
                return false;
            }
    });

        $('#name, #subject, #email,#message').focus(function(){
            $(this).css({"background":"#ffffff","border":"1px solid #dcdcdc"}).next('.require').text(' *');
        });

        });

And finally, the HTML (PHP Contact page): contact.php

  <!-- Contact Form Start //-->
  <form action="#" id="contactform"> 
  <fieldset>
  <label>Name </label><input type="text" name="name" class="textfield" id="name" value="" /><span class="require"> *</span>
  <div class="clear"></div>
  <label>E-mail </label><input type="text" name="email" class="textfield" id="email" value="" /><span class="require"> *</span>
  <div class="clear"></div>
  <label>Subject </label><input type="text" name="subject" class="textfield" id="subject" value="" /><span class="require"> *</span>
  <div class="clear"></div>    
  <label>Message </label><textarea name="message" id="message" class="textarea" cols="2" rows="2"></textarea><span class="require"> *</span>
  <div class="clear"></div> 
  <input type="submit" name="submit" class="buttoncontact" id="buttonsend" value="Send Now" />
  <span class="loading" style="display: none;">Please wait..</span>
  <div class="clear"></div>
  </fieldset> 
  </form>
  <!-- Contact Form End //-->

What is up with these scripts? They never work, on any host/environment I've used them on. I can send email with my own PHP scripts, but for once i would just like to use the one that's built into the template so i don't have to go picking this and that out so it doesn't break down.

And I'm pretty sure there shold be a username/password thing in there, since my Web Host doesn't allow LocalHost.

Can someeone please help? There are no warnings, errors etc..


There are likely two problems here:

  1. Your host doesn't allow calls to mail without authentication of some sort. Some companies (i.e. Fasthosts) don't allow you to send an email without the from address being set, and being an active account that they manage. You should read the documentation from the hosting company to check how they are doing things.

  2. The mail is being sent to your spam folder.

Also, I'd check the $vname variable – is it being set?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜