title: PHPMailer Change the senders name
body: <p>I'm having trouble setting the name that's sent with mailings sent using the PHPMailer class.</p>
  
  <p>I've written the following function so that it can be used in a similar way the php's bulit in <code>mail()</code> function.</p>
  
  <pre><code>function pmail($to, $subject, $message, $headers = "", $attachments = "")
  {
      date_default_timezone_set('Europe/London');
  
      require_once($_SERVER['DOCUMENT_ROOT']."/lib/inc/class.phpmailer.php");
      //include($_SERVER['DOCUMENT_ROOT']."/lib/inc/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
  
      $defaultEmail = "reply@example.com";
      $defaultEmailName = "Web Mailer";
  
      $mail = new PHPMailer();
  
      $mail-&gt;IsSMTP();                                // telling the class to use SMTP
      $mail-&gt;Host       = "mail.example.com";         // SMTP server
      $mail-&gt;SMTPDebug  = false;                      // enables SMTP debug information (for testing, 1 = errors and messages, 2 = messages only, false = off)
      $mail-&gt;SMTPAuth   = true;                       // enable SMTP authentication
      //$mail-&gt;SMTPSecure = "tls";                    // sets the prefix to the servier
      $mail-&gt;Host       = "mail.example.com";         // sets the SMTP server
      $mail-&gt;Port       = 25;                         // set the SMTP port for the GMAIL server
      $mail-&gt;Username   = "###";                      // SMTP account username
      $mail-&gt;Password   = "###";                      // SMTP account password
      $mail-&gt;SetFrom( ($headers['fromEmail'] != "" ? $headers['fromEmail'] : $defaultEmail), ($headers['fromName'] != "" ? $headers['fromName'] : $defaultEmailName) );
      $mail-&gt;AddReplyTo( ($headers['replyToEmail'] != "" ? $headers['replyToEmail'] : $defaultEmail), ($headers['replyToName'] != "" ? $headers['replyToName'] : $defaultEmailName) );
      $mail-&gt;AddAddress($to);
      $mail-&gt;Subject = $subject;
      $mail-&gt;AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
      $mail-&gt;MsgHTML($message);
  
      foreach($attachments as $attachment) {
          //$mail-&gt;AddAttachment("images/phpmailer.gif");      // attachment example
          $mail-&gt;AddAttachment($attachment);
      }
  
      if(!$mail-&gt;Send()) {
          //echo "Mailer Error: ".$mail-&gt;ErrorInfo;
          return false;
      } else {
          //echo "Message sent!";
          return true;
      }
  }
  </code></pre>
  
  <p>When testing with something like so;</p>
  
  <p><code>pmail("test@test.com", "test email", "test message here");</code></p>
  
  <p>Everything works fine, the from address shows up as <code>reply@example.com</code> in the headers as expected, however the name that I see in the inbox of the recipient is not <code>Web Mailer</code> its the default account associated with the user whos credentials are used to send the email.
  In the headers the from name does show up as Web Mailer, but its the inbox where I want to see it</p>
  
  <p>We are unable to set up more user accounts on our system to allow us to just make a new one with the desired name and email, therefore we have to send it via an existing user account. 
  In this case mine, and emails get sent with my name attached, but we want the name to show up as Web Mailer.</p>
  
  <p>Is this even possible?</p>