I'm trying to set up SMTP for my custom contact form.
I have placed the latest PHPMailer folder in my theme folder.
I created a page template for Contact Form and added the code for the contact form in it and below it I added the SMTP code like below,
<?php
require("PHPMailer/class.PHPMailer.php");
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = false; // Enable SMTP authentication
//$mail->Username = ''; // SMTP username
//$mail->Password = ''; // SMTP password
//$mail->SMTPSecure = 'tls'; // Enable TLS encryption, <code>ssl</code> also accepted
$mail->Port = 25; // TCP port to connect to
$mail->setFrom($email, $sendername);
$mail->addAddress('test@gmail.com', 'Joe User'); // Add a recipient
//$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo($email, $sendername);
$mail->addCC('test@testmail.com');
//$mail->addBCC('bcc@example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Test Mail';
$comment = $comment . "\r\n<br/>" . "<br/>\r\nIP Address: " . $id . "<br/>\r\nUser Agent: " . $browser . "<br/>\r\nUser Agent: " . "<br/>\r\nReferrer: " . $referrer . "<br/>\r\nCity: " . $city . "<br/>\r\nRegion: " . $region . "<br/>\r\nCountry: " . $country . "<br/>\r\nLatitude: " . $latitude . "<br/>\r\nLongitude: " . $longitude;
$mail->Body = $comment;
$mail->AltBody = $comment;
if($sendernameErrFlag == 0 && $emailErrFlag == 0 && $subjectErrFlag == 0 && $commentErrFlag == 0) {
$mail->send();
echo "hi";
$pagelink = the_permalink();
echo '<div id="popup1" class="overlay">
<div class="popup">
<a class="close" href="' . $pagelink . '">×</a>
<div class="content">
Message sent successfully!!!
</div>
</div>
</div>';
//echo '<script>alert("Message sent successfully!!!");</script>';
} else {
$sendernameErrFlag = $emailErrFlag = $subjectErrFlag = $commentErrFlag = 2;
}
?>
But when I submit the contact form, wordpress stops executing code when it reaches the line with the require() is written. Any and all code writting below it is not executed.
If I place the require() above the form then the form also doesn't display in the page. If I place it in the header the whole page doesn't display.
What seems to be the problem here? Why is WordPress not accepting and executing the require()?