Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer from is showing as Root User

Tags:

php

I am using PHP Mailer to send emails and i am using SMTP

here is the code i am using:

$email = new PHPMailer();

            $email->IsSMTP(); // telling the class to use SMTP
            $email->Host       = "mail.integradigital.co.uk"; // SMTP server
            $email->SMTPDebug  = 2; // enables SMTP debug information (for testing)
                                                       // 1 = errors and messages
                                                       // 2 = messages only
            $email->SMTPAuth   = true;  // enable SMTP authentication
            $email->Host       = "mail.integradigital.co.uk"; // sets the SMTP server
            $email->Port       = 26;    // set the SMTP port for the GMAIL server
            $email->Username   = "sending@************.co.uk"; // SMTP account username
            $email->Password   = "********";        // SMTP account password

            $email->SetFrom($result["emailfrom"]);
            $email->FromName($result["emailfrom"]);

            $email->Subject   = $result["subject"];
            $email->Body      = $result["message"];

but its sending and showing as from Root User - root@localhost

i know i can change this in the class.phpmailer.php file but i want to be able to set it in the code above

is this possible?

like image 562
charlie Avatar asked Oct 17 '13 21:10

charlie


People also ask

Does PHPMailer work on localhost?

If the web application is built with PHP, the mail() function is used to send email from the script using PHP. But the PHP mail() function will not work in localhost.

Where is PHPMailer installed?

php” file you can use to include the installed libraries, in this case PHPMailer. This file is located under the “vendor” directory by default, although you can configure Composer to use a different directory name.

Is PHPMailer SMTP?

PHPMailer can use a non-local mail server (SMTP) if you have authentication. Further advantages include: It can print various kinds of error messages in more than 40 languages when it fails to send an email. It has integrated SMTP protocol support and authentication over SSL and TLS.


3 Answers

Okay, in short:

$email->From = "[email protected]";
$email->FromName = "Support Team";

This worked out for me.

like image 129
Fancy John Avatar answered Oct 02 '22 21:10

Fancy John


Wrap the whole thing in a try catch. And initialize phpmailer with exceptions enabled

$email = new PHPMailer(true);

It looks like the default values are used. So something goes wrong when calling setFrom(). And it's failing silently because it returns false without exceptions enabled.

try {
  // your mail code here
} catch (phpmailerException $e) {
  echo $e->getMessage();
}

And change the setting of email and from name to:

$email->setFrom($result["emailfrom"], $result["emailfrom"]);

FromName is a property not a method.

like image 26
tlenss Avatar answered Oct 02 '22 22:10

tlenss


class.phpmailer.php file contains the "var $FromName = 'Root User';" section which can be changed to "Desired Name" from "Root User" and have your job done.

like image 29
Kipngetich Yegon Avatar answered Oct 02 '22 21:10

Kipngetich Yegon