SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Contact form / php / phpmailer

    So my problem is my contact form that is on my site currently will not send emails to me or my websites email addresses.

    I am new to php and html, I have signed up with Postmark to handle the SMTP and created a server through them to process the mail. Also, downloaded the phpmailer.php and smtp.php files from Github.

    When I FTP my contact.php file & phpmailer files to my web server I immediately get a fatal error. But when I take out the

    $mail->IsSMTP();
    $mail->SMTPAuth = true;

    the page renders fine, but unable to send an email. Looking for help on this, on day 6 of frustration.

    You can view my current code with the email/username/passwords taken out here:

    PHP Code:
    <?php

    $mail
    ->IsSMTP();
    $mail->SMTPAuth true;
    $mail->Host "smtp.postmarkapp.com";
    $mail->Port 25;
    $mail->Username "@$@$@@$@@@$$@@";
    $mail->Password "@$@$@$@$@$@$@@";

    if (
    $_SERVER["REQUEST_METHOD"] == "POST") {
        
    $name trim($_POST["name"]);
        
    $email trim($_POST["email"]);
        
    $message trim($_POST["message"]);


        if (
    $name == "" OR $email == "" OR $message == "") {
            echo 
    "You must specify a value for name, email address, and message.";
            exit;
        }

        foreach( 
    $_POST as $value ){
            if( 
    stripos($value,'Content-Type:') !== FALSE ){
                echo 
    "There was a problem with the information you entered.";    
                exit;
            }
        }

        if (
    $_POST["address"] != "") {
            echo 
    "Your form submission has an error.";
            exit;
        }

        require_once(
    "inc/phpmailer/class.phpmailer.php");
        
    $mail = new PHPMailer();

        if (!
    $mail->ValidateAddress($email)){
            echo 
    "You must specify a valid email address.";
            exit;
        }

        
    $email_body "";
        
    $email_body $email_body "Name: " $name "<br>";
        
    $email_body $email_body "Email: " $email "<br>";
        
    $email_body $email_body "Message: " $message;

        
    $mail->SetFrom($email$name);
        
    $address "@@$@$@email.com";
        
    $mail->AddAddress($address"@$$@@$$@");
        
    $mail->Subject    "Contact Form Submission | " $name;
        
    $mail->MsgHTML($email_body);

        if(!
    $mail->Send()) {
          echo 
    "There was a problem sending the email: " $mail->ErrorInfo;
          exit;
        }

        
    header("Location: contact.php?status=thanks");
        exit;
    }
    ?><?php 
    $pageTitle 
    "Contact";
    $section "contact";
    include(
    'inc/header.php'); ?>

        <div class="section page">

            <div class="wrapper">

                <h1>Contact</h1>

                <?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
                <div id="contact-text">
                    <p>Thanks for the email!  We&rsquo;ll be in touch shortly!</p>
                </div>
                <?php } else { ?>

                    <div id="contact-text">
                        <p>We&rsquo;d love to hear from you!<br>Complete the form to send us an email.</p>
                    </div>        
                    <form method="post" action="contact.php">

                        <table>
                            <tr>
                                <th>
                                    <label for="name">Name</label>
                                </th>
                                <td>
                                    <input type="text" name="name" id="name">
                                </td>
                            </tr>
                            <tr>
                                <th>
                                    <label for="email">Email</label>
                                </th>
                                <td>
                                    <input type="text" name="email" id="email">
                                </td>
                            </tr>
                            <tr>
                                <th>
                                    <label for="message">Message</label>
                                </th>
                                <td>
                                    <textarea name="message" id="message"></textarea>
                                </td>
                            </tr>                    
                        </table>
                        <input type="submit" value="Send">

                    </form>

                <?php ?>

            </div>

        </div>

    <?php include('inc/footer.php'?>
    Thank you in advance for your detailed responses, since I am new and need some help walking through this process.

    -Ryan
    Last edited by cpradio; Sep 10, 2013 at 05:21.

  2. #2
    SitePoint Addict
    Join Date
    Aug 2006
    Location
    Nantwich, Cheshire
    Posts
    278
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I don't see any code there, just a screen with black at the top, and white at the bottom, and a few links. I can see it's there somewhere if I view source on the page, but it's html-encoded so unreadable.

    Can you just post the code here so it can be looked at ?
    http://www.firenza.net - my homage to a car from the 1970s

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,808
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Since codepen isn't really a great vessel for posting code, I've coped the code here and placed it in the original posting.
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  4. #4
    SitePoint Addict
    Join Date
    Aug 2006
    Location
    Nantwich, Cheshire
    Posts
    278
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Can you post the error message you get when you have those two lines in place? I can see that if your smtp server requires auth and you haven't set it, it's not going to send the email. I've seen some talk that the isSMTP() method is deprecated, but then more talk that it is not. So the error message is needed.

    Cheers cpradio, I couldn't see code on that page at all.
    http://www.firenza.net - my homage to a car from the 1970s


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •