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?
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.
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.
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.
Okay, in short:
$email->From = "[email protected]";
$email->FromName = "Support Team";
This worked out for me.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With