0

Want to take input from a contact form and email that to an address. Using PHPMailer (the newest version from GitHub) and Google's SMTP.

Config variables

<?php
    $host = "smtp.google.com";
    $port = 587;
    $username = "********@gmail.com";
    $password = "********";
?>

Form to email script

<?php
    require_once('PHPMailer-master/class.phpmailer.php');
    include('../../../settings/config.php');

    $mail = new PHPMailer();

    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = "tls";
    $mail->Host = gethostbyname($host);
    $mail->SMTPDebug  = 2;
    $mail->Port = $port;

    $mail->Username = $username;
    $mail->Password = $password;

    $mail->SetFrom($username, 'Webform');
    $mail->AddReplyTo($_POST['email'], $_POST['name']);

    $mail->Subject = "CONTACT REQUEST";
    $mail->Body = "\nName: " . $_POST['name'] . "\n" . "Email: " .
        $_POST['email'] . "\n" . "Subject: " . $_POST['subject'] . "\n" 
        . "--BEGIN MESSAGE--\n\n" . $_POST['message'] . 
        "\n\n--END MESSAGE--";
    $mail->AddAddress($username);

    if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else { echo "Message sent!"; }
?>

If I run this I get a blank screen like there's a syntax error, it doesn't throw a debug message at all. I've isolated it down to $mail->Send() changing the code to the following:

<?php
    .
    .
    .
    /* if(!$mail->Send()) {
        .
        .
        .
    } else { . . . } */

    echo "some message";
?>

The code will run properly and will echo some message if it is changed to this. I'm not sure what the problem is, I've changed around various things to try and get it working but not got anywhere. Is it possible there is some issue with my server configuration?

Thanks for any suggestions,

macourtney7
  • 521
  • 2
  • 10
  • 24

0 Answers0