1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Contact Form Problems

Discussion in 'Web Design & Development' started by howard.a.s, Jul 4, 2019.

Thread Status:
Not open for further replies.
Advertisement
  1. howard.a.s

    howard.a.s Thread Starter

    Joined:
    Jul 22, 2005
    Messages:
    496
    Hi! I was wondering whether anyone reading this post might be able to help me to understand why the contact field of http://www.themetaldetective.co.uk/alissa2/ refuses to send messages to a designated email address. Here is the contact form code:

    PHP:
    <?php


    // Email address verification

    function isEmail($email) {
        return(
    preg_match("/^[-_.[:alnum:]][email protected]((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"$email));
    }

    if(
    $_POST) {

        
    // Enter the email where you want to receive the notification when someone subscribes
        
    $emailTo 'myemail.com';

        
    $subscriber_email addslashes(trim($_POST['email']));

        if(!
    isEmail($subscriber_email)) {
            
    $array = array();
            
    $array['valid'] = 0;
            
    $array['message'] = 'Insert a valid email address!';
            echo 
    json_encode($array);
        }
        else {
            
    $array = array();
            
    $array['valid'] = 1;
            
    $array['message'] = 'Thanks for your subscription!';
            echo 
    json_encode($array);

            
    // Send email
            
    $subject 'New Subscriber (alissa)!';
            
    $body "You have a new subscriber!\n\nEmail: " $subscriber_email;
            
    // uncomment this to set the From and Reply-To emails, then pass the $headers variable to the "mail" function below
            //$headers = "From: ".$subscriber_email." <" . $subscriber_email . ">" . "\r\n" . "Reply-To: " . $subscriber_email;
            
    mail($emailTo$subject$body);
        }

    }

    ?>
    I have tried swapping out myemail.com for the email address I'd like the form to send messages to, and although the form states that the information has been successfully sent, nothing seems to arrive in my inbox.
    PHP:
      $emailTo 'myemail.com';
    Perhaps worth mentioning that, in the past, when trying to get other forms to send, my web host has advised:
    So, if I upload the form to, for instance, mynewwebsite.com, the "FROM" email address needs to be something in line with [email protected]. I have checked the existing code, but can't seem to see where I would make the necessary changes.

    Please can anyone help?

    Any constructive advice and suggestions would be gratefully received.
     
  2. colinsp

    colinsp

    Joined:
    Sep 5, 2007
    Messages:
    2,278
    First Name:
    Colin
    That code doesn't look right to me, you need to check back with where you got it from.

    Plus you have not done what the code tells you to do on these two lines:

    PHP:
        // uncomment this to set the From and Reply-To emails, then pass the $headers variable to the "mail" function below
            //$headers = "From: ".$subscriber_email." <" . $subscriber_email . ">" . "\r\n" . "Reply-To: " . $subscriber_email;
     
  3. howard.a.s

    howard.a.s Thread Starter

    Joined:
    Jul 22, 2005
    Messages:
    496
    Hi Colin, and thanks for your reply.

    I am not sure that I'll get much in the way of advice from the creator, as this is a template downloaded free from the web. I can give it a shot though. As for the two lines of code you refer to, I did spend some time pondering over what I should do with this, only not having hardly any understanding of PHP I am uncertain as to how I would uncomment this section of code so as to hopefully enable the form. Would I wrap the code section in <!-- code goes here --> or /* code goes here */ so as to render it inoperative? and what is meant by 'then pass the $headers variable to the "mail" function below'?
     
  4. howard.a.s

    howard.a.s Thread Starter

    Joined:
    Jul 22, 2005
    Messages:
    496
    I've been doing a little bit more Googling and came up with this page https://www.tutorialrepublic.com/php-tutorial/php-send-email.php which includes the following code for a simple sendmail
    PHP:
    <?php
    $to 
    '[email protected]';
    $subject 'Marriage Proposal';
    $message 'Hi Jane, will you marry me?';
    $from '[email protected]';
     
    // Sending email
    if(mail($to$subject$message)){
        echo 
    'Your mail has been sent successfully.';
    } else{
        echo 
    'Unable to send email. Please try again.';
    }
    ?>
    If I swap out my existing subscribe.php for this script, would the existing html likely need no alteration for the form to send. Obviously I'll need to alter to my own to and from email addresses and alter the subject and message, but otherwise looks okay?
     
  5. colinsp

    colinsp

    Joined:
    Sep 5, 2007
    Messages:
    2,278
    First Name:
    Colin
    That should work BUT it isn't secure.

    But you probably need to capture more from your form like their email address etc and add that to the email.
     
  6. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,357
    First Name:
    Jim
    Sorted Howard?
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1229531

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice