Forums

[resolved] [closed] SMTP problem in Contact Page (4 posts)

  1. nima OL
    Member
    Posted 1 year ago #

    I'm almost done designing my very first website... about to put it into wordpress...

    In my Contact page I want to test my mail function to see if that works, I use WAMP and when I click on Submit button it says Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\html\contactengine.php on line 30

    My codes:
    HTML:

    <form method="POST" action="contactengine.php" id="commentForm">
                      <fieldset>
                      <div id="formLeft">
    
                        <label for="Name">name:</label>
                        <div class="input-bg">
                          <input type="text" name="Name" id="Name" class="required" minlength="2" />
                        </div>
    
                        <label for="City">city:</label>
                        <div class="input-bg">
                          <input type="text" name="Subject" id="Subject" class="required" minlength="2" />
                        </div>
    
                        <label for="Email">Email:</label>
                        <div class="input-bg">
                          <input type="text" name="Email" id="Email" class="required email" />
                        </div>
    
                      </div>
    
                      <div id="formRight">
                        <td><label for="Message">Message:</label></td>
                        <div class="message-bg">
                          <textarea name="Message" id="Message" rows="20" cols="20" class="required"></textarea>
                        </div>
                        <br />
                        <input type="image" src="images/send-button.jpg" name="submit" value="Submit" class="submit-button" />
                      </div>
    
                      <div class="clear"></div>
                      </fieldset>
                    </form>

    And PHP page:

    <?php
    
    // CHANGE THE VARIABLES BELOW
    
    $EmailFrom = "REDACTED";
    $EmailTo = "REDACTED";
    $Subject = "Contact Form Submission";
    
    $Name = Trim(stripslashes($_POST['Name']));
    $Email = Trim(stripslashes($_POST['Email']));
    $Message = Trim(stripslashes($_POST['Message'])); 
    
    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";
    
    // send email
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    
    // redirect to success page
    // CHANGE THE URL BELOW TO YOUR "THANK YOU" PAGE
    /*
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.html\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
    }
    */
    ?>

    I need to set it up on my Gmail account... Please help me with it, it took my whole day after checking tons of tutorials :(

  2. cubecolour
    ɹoʇɐɹǝpoɯ
    Posted 1 year ago #

    This doesn't seem to have anything to do with WordPress. The script you are using is not a WordPress plugin, but seems to be a generic php script used for otherwise static html or sites.

    Install a contact form plugin such as contact form 7 (others are available). Personally I wouldn't be concerned about getting it working locally if I was using WAMP on Windows - it should just work once you have it on linux hosting.

  3. nima OL
    Member
    Posted 1 year ago #

    Thanks for the reply, I know, people here have experiences outside of WP too so I thought I can give it a shot and call for help!

    I won't be using plug-in for this one, I want to have that in my coding process.

  4. Alas, while you CAN give a shout-out, cubecolour's right.

    This isn't a WP code or WP related question. I'm closing the topic.

    Also I removed your EMAIL ADDRESS from your code. Unless you actually like getting spam, you shouldn't post it.

Topic Closed

This topic has been closed to new replies.

About this Topic