I made a custom class function for setting up the basic information needed by PHPMailer (so I don't need to input it in everytime). Here is the exact code of the function.
<?php
class PHPMailer {
public static function send() {// I will just add here the addAddress
require_once 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "validusername";
$mail->Password = "validpassword";
$mail->setFrom('validusername', 'Valid Username');
$mail->addAddress('googol8080@gmail.com', 'Googol');
$mail->Subject = "Subject";
$mail->Body = "<a href=\"www.google.com\">www.google.com</a>";
$mail->IsHTML(true);
if (!$mail->send()) {
return "Error sending message" . $mail->ErrorInfo;
} else {
return "Message sent!";
}
}
}
So far it is working on my localhost, but I have questions:
- Is this a good practice?
- Is the code okay?
- Is there any drawback/s about this?
- If there is need to optimize here for performance, what do I need to do to make it happen?
I am really new in PHP and PHPMailer any small answers might help me, thanks.