You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A few days ago, I was confused why I was not getting a "headers already sent" error when I should have been. Turns out there is something called output buffering of which I have now taken advantage.
10/15/2019
I was on a tech support call yesterday trying to use PHP - specifically, the PHPMailer framework - to send emails for contact forms, email verification, and forgot password emails. Nothing was working for the SMTP username and password and what not. They told me it was 'localhost:25' and then GoDaddy told me I could not use personal emails. Today, I used the cPanel email I have, admin@bforborum.com, which was NOT purchased, but free. I got rid of all the username and password stuff and anything to do with SMTP and replaced it with isMail(). It worked.
function sendEmail($subject, $body, $email = 'admin@bforborum.com', $aftermessage = '') {
// Load Composer's autoloader
require 'vendor/autoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isMail(); // Send using SMTP
$mail->Port = 25; // TCP port to connect to
//Recipients
$mail->setFrom('admin@bforborum.com', 'Borum CEO Varun Singh');
$mail->addAddress($email); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = strip_tags($body);
$mail->send();
echo $aftermessage;
} catch (Exception $e) {
echo "Message could not be sent. A mailing error occured. ";
}