-
Notifications
You must be signed in to change notification settings - Fork 0
PHP Learning Curves
10/26/2019
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, [email protected], 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 = '[email protected]', $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('[email protected]', '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. ";
}