Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7808671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:12:02+00:00 2026-06-02T03:12:02+00:00

I am using PHPMailer but I think it’s taking too many lines and feel

  • 0

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
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:12:03+00:00Added an answer on June 2, 2026 at 3:12 am
    function New_Mail($body, $subject, $altBody, $wordwrap)
    {
        $mail             = new PHPMailer();
    
        $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    = $subject;
        $mail->AltBody    = $altBody; //Text Body
        $mail->WordWrap   = $wordwrap; // set word wrap
    
        $mail->MsgHTML($body);
        $mail->AddReplyTo("replyto@yourdomain.com","Admin");
        $mail->SMTPDebug = 1;
        $mail->IsHTML(true); // send as HTML
    
        return $mail;
    }
    
    $mail = New_Mail("this is the body", "Welcome", "Another body", 100);
    if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
    // nothing is displayed
    }
    

    Now you reuse that function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using google, yahoo and AOL smtp and PHPMailer how many mails can be sent
Hay I'm using PHPMailer to send some simple emails, however the function SetFrom() doesn't
I'm using PHPMailer and it uses fsockopen to access the SMTP server. But the
I'm using PHPMailer for a while now and never really had any problems, but
I am using phpmailer to send e-mails and had some problems with sending on
Im using PHP's mail() function to send some emails. But all my mails land
Why? I can send via mail() in PHP but I can't send via PHPMailer
using PHPMailer's AddAttachment method on PHP 5, it seems I can't get any mail
I'm trying to send out mail using Google's SMTP in combination with PHPMailer, but
I'm trying to send SMTP e-mails using PHPMailer, but I keep getting this error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.