Ortund
Ortund

Reputation: 8245

Mail send with PHPMailer doesn't work

So I'm trying to use PHPMailer to handle the email form on my website.

I wrote the code here based on a tutorial I found.

<?php
        error_reporting(E_ALL);
        require_once("class.phpmailer.php");
        include("class.smtp.php");

        $email = new PHPMailer();

        //
        // Set server details for send
        //
        $email->IsSMTP();
        $email->Host = "mail.loganyoung.za.net";
        $email->Port = 25;
        $email-SMTPAuth = true;
        $email->Username = "<my email>";
        $email->Password = "<my password>";

        //
        // Send mail from the contact form
        //
        $to = "<my email>";
        $from = $_POST["from"];
        $name = $_POST["name"];
        $subject = "From web: ".$_POST["subject"];
        $message = $_POST["message"];

        $body = "<p>Hi Logan,</p>";
        $body .= "<p>You have received a new query on your website.<br />Please see below:</p>";
        $body .= "<p>";
        $body .= str_replace("\r\n", "<br />", $message);
        $body .= "</p>";

        $email->SetFrom($from, $name);
        $email->AddReplyTo($from, $name);
        $email->AddAddress($to, "LoganYoung.za.net");
        $email->Subject = $subject;
        $email->Body = $body;
        $email->IsHTML = true;

        session_start();
        if(!$email->Send()) {          
                $_SESSION["mailresult"] = "success";
                echo "success";
        } else {
                echo "<p>Failed:</p><p>".$email->ErrorInfo."</p>";
                $_SESSION["mailresult"] = "failed";
                $_SESSION["mailerror"] = $email->ErrorInfo;
        }

?>

I figure possible reasons for it not sending could be...

As a means of eliminating possibilities, can anyone spot anything wrong with the code here? If so, what's wrong, and how do I fix it?

Thanks in advance!

Upvotes: 0

Views: 2274

Answers (1)

Efekan
Efekan

Reputation: 1505

$email-SMTPAuth = true;

Isn't that supposed to be:

$email->SMTPAuth = true;

Upvotes: 1

Related Questions