I am using PHPMailer but I think it’s taking too many lines and feel I can make it more concise. Some of the parameters below are redundant because everything is gonna be sent from the same email address.
I’m actually asking if I can put the parameters that are always the same somewhere else (From, FromName, Username, Password, Host,Post,SMTPSecure, SMTPAuth)
How can I do it? Thanks in advance. Regards
My code is:
include("classes/phpmailer/class.phpmailer.php");
include("classes/phpmailer/class.smtp.php"); // note, this is optional
$mail = new PHPMailer();
$body = 'This is the body';
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = "myemailaddress@gmail.com"; // GMAIL username
$mail->Password = "mypassword"; // GMAIL password
$mail->From = "myemailaddress@gmail.com";
$mail->FromName = "Admin";
$mail->Subject = "Welcome";
$mail->AltBody = 'This is the body'; //Text Body
$mail->WordWrap = 100; // set word wrap
$mail->MsgHTML($body);
$mail->AddReplyTo("replyto@yourdomain.com","Admin");
$mail->SMTPDebug = 1;
$mail->AddAddress($email,$firstname." ".$surname);
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
// nothing is displayed
}
Now you reuse that function.