145 posts
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
LovelessDesign
says

Hi,

I have taken parts of the code from a tutorial two months ago and it worked. Now I tried my Contact Page again (online. not on a local server) and I don’t get any Emails anymore.

I always get the text message “Thank you for your mail…” I also get in the “if(!isset($hasError)) {” (tried it with an echo).

Also tried it with just this code inside the isset and didn’t work
$emailTo = "example@example.com";
wp_mail('example@example.com', 'subject', 'message');

Here’s the code (without the contact form):

$nameError ="";
$emailError ="";
$commentError ="";

if(isset($_POST['submitted'])) {
    if(trim($_POST['contactName']) === '') {
        $nameError = ' <span class="errormessage">'.__('Please enter your Name.','LovelessDesign').'</span>';
        $hasError = true;
    } else {
        $name = trim($_POST['contactName']);
    }

    if(trim($_POST['email']) === '')  {
        $emailError = ' <span class="errormessage">'.__('Please enter your Email Address.','LovelessDesign').'</span>';
        $hasError = true;
    } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
        $emailError = ' <span class="errormessage">'.__('You entered an invalid Email Address.','LovelessDesign').'</span>';
        $hasError = true;
    } else {
        $email = trim($_POST['email']);
    }

    if(trim($_POST['comments']) === '') {
        $commentError = ' <h5><span class="errormessage">'.__('Please enter a Message.','LovelessDesign').'</span></h5>';
        $hasError = true;
    } else {
        if(function_exists('stripslashes')) {
            $comments = stripslashes(trim($_POST['comments']));
        } else {
            $comments = trim($_POST['comments']);
        }
    }

    if(!isset($hasError)) {
        $emailTo = ot_get_option( 'contact_email' );
        if (!isset($emailTo) || ($emailTo == '') ){
            $emailTo = get_option('admin_email');
        }
        $subject = __('Contact Form, from ','LovelessDesign').$name;
        $body = "Name: $name \nEmail: $email \n\nComments: $comments";
        $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

        wp_mail($emailTo, $subject, $body, $headers);
        $emailSent = true;
    }
} 

....
<?php if(isset($emailSent) && $emailSent == true) { ?>

     <h3><?php _e('Thank you for your Email.','LovelessDesign'); ?></h3>
     <?php _e('We have received your message and will respond as soon as possible.','LovelessDesign'); ?>

<?php } else {

....

Any Ideas?

Thanks

905 posts
  • Author Level 3
  • Affiliate Level 1
  • Collector Level 2
  • 4 Years of Membership
+4 more
infuse01
says

Yeah I have an idea: Simply stop embedding your contact forms into your themes and try better to support existing form plugins since “forms” shouldn’t be part of themes and you’re always limited (and you limit your clients too) with the customization of those forms.

Try Contact Form 7 – create some custom forms and style the output according to the overall design. :D

709 posts
  • Affiliate Level 2
  • Author Level 5
  • Beta Tester
  • Collector Level 2
+2 more
ChillThemes
says


Yeah I have an idea: Simply stop embedding your contact forms into your themes and try better to support existing form plugins since “forms” shouldn’t be part of themes and you’re always limited (and you limit your clients too) with the customization of those forms.
Terrible advice.

How is that terrible advice? Care to explain? Just support Contact Form 7 and/or Gravity Forms and save yourself some time. Plugins were made for a reason, don’t be afraid to support them. Just include a list of recommended plugins in your documentation, that’s what I do for shortcodes, etc.

157 posts
  • Affiliate Level 2
  • Author Level 8
  • Collector Level 1
  • Elite Author
+3 more
mountainthemes
says
How is that terrible advice? Care to explain? Just support Contact Form 7 and/or Gravity Forms and save yourself some time. Plugins were made for a reason, don’t be afraid to support them. Just include a list of recommended plugins in your documentation, that’s what I do for shortcodes, etc.

+1

905 posts
  • Author Level 3
  • Affiliate Level 1
  • Collector Level 2
  • 4 Years of Membership
+4 more
infuse01
says

I wouldn’t recommend using wp_mail. Try this:
<? if($_SERVER['REQUEST_METHOD'] == "POST" ) {

    $destination = 'john@doe.com'; // change this to your email.

    // ##################################################
    // DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING
    // ##################################################

    $email   = $_POST['email'];
    $name     = $_POST['contactName'];
    $message = $_POST['comments'];
    $subject = $name;
    $headers = "From: ".$name." <".$email.">\r\n" .
             "Reply-To: ".$name." <".$email.">\r\n" .
             "X-Mailer: PHP/" . phpversion() . "\r\n" .
             "MIME-Version: 1.0\r\n" .
             "Content-Type: text/plain; charset=\"iso-8859-1\r\n" .
             "Content-Transfer-Encoding: 8bit\r\n\r\n";

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

}

Yeah I have an idea: Simply stop embedding your contact forms into your themes and try better to support existing form plugins since “forms” shouldn’t be part of themes and you’re always limited (and you limit your clients too) with the customization of those forms.
Terrible advice.

Based on your advice it seems pretty much that you doesn’t care about Wordpress and its core functions. So I wouldn’t expect any different answer from someone like you…

2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 more
revaxarts
says

Have to agree with infuse. Your version is bad coding and open for injections. wp_mail is much better if you use WordPress

145 posts
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
LovelessDesign
says

Thanks guys. But it also doesn’t work with PHP mail and also not with Contact Form 7. There might be something wrong with my host

by
by
by
by
by
by